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"); } }
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')); } }
public function __construct(Am_Protect_Databased $plugin, $db = null, $table = null, $recordClass = null, $key = null) { parent::__construct($plugin, $db, $table, $recordClass, $key); $this->setFieldsMapping(array(array(Am_Protect_Table::FIELD_LOGIN, 'username'), array(Am_Protect_Table::FIELD_NAME, 'name'), array(Am_Protect_Table::FIELD_EMAIL, 'email'), array(Am_Protect_Table::FIELD_PASS, 'password'), array(Am_Protect_Table::FIELD_ADDED_SQL, 'registerDate'), array(Am_Protect_Table::FIELD_GROUP_ID, 'gid'))); $this->setGroupsTableConfig(array(Am_Protect_Table::GROUP_TABLE => "?_core_acl_aro", Am_Protect_Table::GROUP_GID => 'group_id', Am_Protect_Table::GROUP_UID => 'value')); }
function removeRecord(Am_Record $record) { parent::removeRecord($record); $this->_db->query('delete from ?_usermeta where user_id = ?', $record->pk()); if ($this->getPlugin()->getConfig('simple_press')) { $this->removeFromSimplePress($record); } }
function updateFromAmember(Am_Record $record, User $user, $groups) { parent::updateFromAmember($record, $user, $groups); $this->updateMetaTags($record, $user); }