vgrem / phpSPO

Microsoft 365 Library for PHP.
MIT License
360 stars 117 forks source link

Retrieving a large list of items from sharepoint - new method confusion #330

Open stuartpaulin opened 1 year ago

stuartpaulin commented 1 year ago

Referring to the 3.0.1 change that meant the old getItems() now only returns 100 items and the replacement is a getAll().

I note from the notes the suggested method is: $ctx = (new ClientContext($siteUrl))->withCredentials($credentials); $list = $ctx->getWeb()->getLists()->getByTitle("--large list title--");

$allItems = $list->getItems()->getAll(5000, function ($returnType){ print("{$returnType->getPageInfo()} items loaded...\n"); })->executeQuery();

In the large items example file similar but different code is suggested.

I replaced my function:

private function getSharePointListByTitle($titleURL)
{
    $list = $this->ctx->getWeb()->getLists()->getByTitle($titleURL);

    $items = $list->getItems();
    $this->ctx->load($items);
    $this->ctx->executeQuery();

    return $items;
}

with

private function getSharePointListByTitle($titleURL)
{
    $list = $this->ctx->getWeb()->getLists()->getByTitle($titleURL);

    $allItems = $list->getItems()->getAll(5000, function ($returnType){
        print("{$returnType->getPageInfo()} items loaded...\n");
    })->executeQuery();

    return $allItems;
}

But no luck. I can see that 567 items are returned in the sub function and printed to screen, but I can't see how I can extract them to actually use them. Would you expand on the example to explain it please. I'm guesing it is something like another $allItems->getYesReallyGetThemNow(); or something???

Meantime I ended up dropping back to 3.0.0 Thanks heaps

cweiske commented 1 year ago

Commit that brought this breaking change was 89fd826129ed2299c9e6c4bfd971e1f6ed875ff0

ClientObjectCollection.php enhancements, introduced getAll method