/** * This function iterate over a large result set, only processing records in * batches to keep the memory usage reasonable. After a batch has been collected, * a reference to this object is passed to a callback function. That function * will update any columns necessary. This function will the save the changes * and start on a new batch. * * Callback function first argument must be a reference to a vB_DataManager_Multiple object. * Additional arguments should be passed to this function in an array. * * @param string|resource A query result resource or a string containing the query to execute * @param callback The function to call to make changes to the records * @param integer Number of records to process in a batch * @param array Any additional arguments to pass to the callback function */ function batch_iterate($records, $callback, $batch_size = 500, $args = array()) { if (is_string($records)) { $records = $this->dbobject->query_read($records); } $intargs = array(&$this); foreach (array_keys($args) as $argkey) { $intargs[] =& $args["{$argkey}"]; } $counter = 0; while ($record = $this->dbobject->fetch_array($records)) { // this if is seperate because otherwise, if we had // count($records) % $batch_size == 0, $this->children would be empty // so we couldn't call post_save_once(). if ($counter % $batch_size == 0) { $this->reset(); } $this->add_existing($record); $counter++; if ($counter % $batch_size == 0) { call_user_func_array($callback, $intargs); $this->save(true, false); } } $this->dbobject->free_result($records); if ($this->children and $counter % $batch_size != 0) { call_user_func_array($callback, $intargs); $this->save(true, false); } $master =& $this->children[reset($this->primary_ids)]; if ($master) { $master->post_save_once(); } }
/** * Fetches the existing data for the selected user * * @return array Array of [selector][property] = value */ function fetch_existing() { $usercss_result = $this->dbobject->query_read("\n\t\t\tSELECT * FROM " . TABLE_PREFIX . "usercss\n\t\t\tWHERE userid = " . $this->userid . "\n\t\t\tORDER BY selector\n\t\t"); $existing = array(); while ($usercss = $this->dbobject->fetch_array($usercss_result)) { $existing["{$usercss['selector']}"]["{$usercss['property']}"] = $usercss['value']; } $this->dbobject->free_result($usercss_result); return $existing; }
/** * Fetches the existing data for the selected user * * @return array Array of [selector][property] = value */ function fetch_existing() { $usercss_result = $this->dbobject->query_read(" SELECT * FROM " . TABLE_PREFIX . "usercss WHERE userid = " . $this->userid . " ORDER BY selector "); $existing = array(); while ($usercss = $this->dbobject->fetch_array($usercss_result)) { $existing["$usercss[selector]"]["$usercss[property]"] = $usercss['value']; } $this->dbobject->free_result($usercss_result); return $existing; }