Esempio n. 1
0
 public function batchProcess(&$context, Am_BatchProcessor $batch)
 {
     @(list($step, $start) = explode('-', $context));
     $pageCount = 30;
     switch ($step) {
         case 0:
             $q = new Am_Query($this->getTable());
             $count = 0;
             $updated = array();
             foreach ($q->selectPageRecords($start / $pageCount, $pageCount) as $r) {
                 $count++;
                 if (!$this->canUpdate($r)) {
                     continue;
                 }
                 /* @var $r Am_Record */
                 $user = $this->_table->findAmember($r);
                 if (!$user) {
                     // no such records in aMember, disable user record ?
                     $this->_table->disableRecord($r, $this->calculateGroups(null, true));
                 } else {
                     $updated[] = $user->user_id;
                     $this->getTable()->updateFromAmember($r, $user, $this->calculateGroups($user));
                     $pass = $this->getDi()->savedPassTable->findSaved($user, $this->getPasswordFormat());
                     if ($pass) {
                         $this->getTable()->updatePassword($r, $pass);
                     }
                 }
             }
             if (!$count) {
                 $step++;
                 $context = "{$step}-0";
             } else {
                 $this->getDi()->store->appendBlob($this->_batchStoreId, implode(",", $updated) . ",");
                 $start += $count;
                 $context = "{$step}-{$start}";
             }
             break;
         case 1:
             /// now select aMember users not exists in plugin db
             $q = new Am_Query(new UserTable());
             $q->addWhere("(select not find_in_set(t.user_id, s.`blob_value`) \n                              from ?_store s \n                              where s.name=?)", $this->_batchStoreId);
             $count = 0;
             $records = $q->selectPageRecords($start / $pageCount, $pageCount);
             foreach ($records as $user) {
                 $count++;
                 /* @var $user User */
                 $this->onSubscriptionChanged(new Am_Event_SubscriptionChanged($user, array(), array()));
             }
             if (!$count) {
                 $context = null;
                 return true;
             }
             $start += $count;
             $context = "{$step}-{$start}";
             break;
         default:
             throw new Am_Exception_InputError("Wrong step");
     }
 }
Esempio n. 2
0
 public function batchProcess(&$context, Am_BatchProcessor $batch)
 {
     @(list($step, $start) = explode('-', $context));
     $pageCount = 30;
     switch ($step) {
         case 0:
             $q = new Am_Query($this->getTable());
             $count = 0;
             $updated = array();
             foreach ($q->selectPageRecords($start / $pageCount, $pageCount) as $r) {
                 $count++;
                 if (!$this->canUpdate($r)) {
                     continue;
                 }
                 /* @var $r Am_Record */
                 $user = $this->_table->findAmember($r);
                 if (!$user) {
                     // no such records in aMember, disable user record ?
                     $this->_table->disableRecord($r, $this->calculateGroups(null, true));
                 } else {
                     $updated[] = $user->user_id;
                     $this->getTable()->updateFromAmember($r, $user, $this->calculateGroups($user, true));
                     $pass = $this->getDi()->savedPassTable->findSaved($user, $this->getPasswordFormat());
                     if ($pass) {
                         $this->getTable()->updatePassword($r, $pass);
                     }
                 }
             }
             if (!$count) {
                 $step++;
                 $context = "{$step}-0";
             } else {
                 $store = array();
                 foreach ($updated as $v) {
                     $store[] = $v;
                 }
                 $this->getDi()->storeRebuild->setArray($this->_rebuildName, $this->_sessionId, $store, '+3 hour');
                 $start += $count;
                 $context = "{$step}-{$start}";
             }
             break;
         case 1:
             /// now select aMember users not exists in plugin db
             $count = 0;
             $db = $this->getDi()->db;
             $r = $db->queryResultOnly("SELECT t.* from ?_user t left join ?_store_rebuild s on s.user_id = t.user_id and s.rebuild_name = ? and s.session_id = ? \n                    WHERE s.user_id is null LIMIT ?d , ?d", $this->_rebuildName, $this->_sessionId, $start, $pageCount);
             while ($row = $db->fetchRow($r)) {
                 $records[] = $this->getDi()->userTable->createRecord($row);
             }
             foreach ($records as $user) {
                 $count++;
                 /* @var $user User */
                 $this->onSubscriptionChanged(new Am_Event_SubscriptionChanged($user, array(), array()));
             }
             if (!$count) {
                 $context = null;
                 return true;
             }
             $start += $count;
             $context = "{$step}-{$start}";
             break;
         default:
             throw new Am_Exception_InputError(___('Wrong step'));
     }
 }