Created
October 20, 2014 09:55
-
-
Save chardcastle/f3b5eedef975de8f28a3 to your computer and use it in GitHub Desktop.
Traverse array in batch YII Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prototype method for traversing large records in batches | |
* using the YII framework. | |
* | |
* Completed stepper method for restoration rollback solution. | |
* | |
* @todo Include this in main restoartion rollback solution | |
* @return [type] [description] | |
*/ | |
public function actionInspect() | |
{ | |
$offset = Controller::getGlobal ("offsetTitle"); | |
$batchSize = 50; | |
if (empty($offset) || $offset == "finished") | |
{ | |
// Value has not been set or doesn't exist | |
Controller::setGlobal("offsetTitle", 0); | |
$offset = Controller::getGlobal ("offsetTitle"); | |
} | |
$targetRestorationUsers = Yii::app()->params['users']; | |
$users = array_slice($targetRestorationUsers, $offset, $batchSize); | |
if (empty($users)) | |
{ | |
Controller::setGlobal("offsetTitle", "finished"); | |
echo "Finished"; | |
yii::app()->end(); | |
} | |
echo "Traversing from {$offset} to {$batchSize}" . "<br/>"; | |
foreach ($users as $user) | |
{ | |
echo $user["first_name"] . "<br/>"; | |
} | |
$offset += $batchSize; | |
Controller::setGlobal("offsetTitle", $offset); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment