/** * Go through all tables and raise the auto_increment index for each table. * * @param Tx_Contentstage_Domain_Repository_ContentRepository $repository The repository to do the raise for. * @param int $step The step to go up. * @param float $threshold Ensures that there will be at least (1 - threshold) * step auto_increments left between the next remote uid hits the new auto_increment. * @return array An array with additional debug information. * @throws Exception */ public function raiseAutoIncrement($repository, $step, $threshold) { $debug = array(); $debug['tables'] = $tables = $repository->getTables(); $maximumAutoIncrement = 0; foreach ($tables as $tableName => &$table) { $maximumAutoIncrement = max($maximumAutoIncrement, $table['Auto_increment']); } $plusOne = $maximumAutoIncrement % $step > $step * $threshold ? 1 : 0; $debug['plusOne'] = $plusOne; $debug['maximumAutoIncrement'] = $maximumAutoIncrement; $debug['newAutoIncrement'] = $newAutoIncrement = (ceil($maximumAutoIncrement / $step) + $plusOne) * $step + 1; $db = $repository->_getDb(); foreach ($tables as $tableName => &$table) { if (intval($table['Auto_increment']) > 0) { $db->sql_query('ALTER TABLE ' . $db->quoteStr($tableName, $tableName) . ' AUTO_INCREMENT = ' . $newAutoIncrement . ';'); if ($db->sql_error()) { throw new Exception('[' . $tableName . '] ' . $db->sql_error(), self::ERROR_ALTER); } } } return $debug; }
/** * Resolves and pushes dependencies. * * @param Tx_Contentstage_Domain_Repository_ContentRepository $fromRepository Repository to push from. * @param Tx_Contentstage_Domain_Repository_ContentRepository $toRepository Repository to push to. * @return void */ protected function pushDependencies(Tx_Contentstage_Domain_Repository_ContentRepository $fromRepository, Tx_Contentstage_Domain_Repository_ContentRepository $toRepository) { $this->log->log($this->translate('info.push.dependencies'), Tx_CabagExtbase_Utility_Logging::OK); $pageTS = $this->getPageTS(); $tables = $fromRepository->getTables(); $dontPushDependencies = empty($pageTS['pushDependencies']); do { $relations = $fromRepository->getUnresolvedRelations(); $unSynced = $fromRepository->setRelationsSynced(); $this->pushFiles($fromRepository, $toRepository, $relations['__FILE'] ?: array()); $this->pushFiles($fromRepository, $toRepository, $relations['__FOLDER'] ?: array()); foreach ($relations as $table => &$data) { if (is_array($data) && isset($data[0])) { unset($data[0]); } if (substr($table, 0, 2) === '__' || empty($data)) { continue; } if (substr($table, -3) === '_mm') { $localUids = implode(',', array_keys($data)); $toRepository->_sql('DELETE FROM ' . $table . ' WHERE uid_local IN (' . $localUids . ')', false); $where = 'uid_local IN (' . $localUids . ')'; } else { if ($dontPushDependencies) { continue; } else { if ($this->ignoreSyncTables[$table] || !$this->tca->isValidTca($table) || !isset($tables[$table])) { continue; } else { $where = 'uid IN (' . implode(',', array_keys($data)) . ')'; } } } $resource = $fromRepository->findInPageTree(0, $table, '*', $where, '', ''); $this->pushTable($resource, $toRepository); } if ($dontPushDependencies) { break; } } while ($unSynced > 0); $sysLogResource = $fromRepository->findResolvedSysLog(); $this->pushTable($sysLogResource, $toRepository); $sysHistoryResource = $fromRepository->findResolvedSysHistory(); $sysHistoryResource->setTable('sys_history'); $this->pushTable($sysHistoryResource, $toRepository); }