Example #1
0
 /**
  * Converts tables to federated tables
  *
  * @param Tx_Contentstage_Domain_Repository_ContentRepository $slaveRepository The repository to initialize the federated tables.
  * @param Tx_Contentstage_Domain_Repository_ContentRepository $masterRepository The repository which holds the master tables.
  * @param string $table The table to make federated.
  * @param array $remoteLoginData The db information for the remote database to make the tables federated with.
  * @return boolean True if the table was changed to federated, false otherwise.
  * @throws Exception
  */
 public function convertTables(Tx_Contentstage_Domain_Repository_ContentRepository $slaveRepository, Tx_Contentstage_Domain_Repository_ContentRepository $masterRepository, $table, $remoteLoginData)
 {
     //check if table is already federated
     $statusTableRow = $slaveRepository->_sql('SHOW TABLE STATUS LIKE \'' . $table . '\'');
     if (count($statusTableRow) === 0) {
         throw new Exception('Table does not exist in the slave database [' . $table . ']', 1399985904);
     }
     $statusTableRow = current($statusTableRow);
     //if not already federated then federate
     if ($statusTableRow['Engine'] !== 'FEDERATED') {
         $createTableRow = $masterRepository->_sql('SHOW CREATE TABLE ' . $table);
         if (count($createTableRow) === 0) {
             throw new Exception('Table does not exist in the master database [' . $table . ']', 1399985905);
         }
         $createTableRow = current($createTableRow);
         $createTable = trim(preg_replace('/ENGINE=[^ ]+/i', 'ENGINE=FEDERATED', $createTableRow['Create Table']));
         if (substr($createTable, -1) === ';') {
             $createTable = substr($createTable, 0, -1);
         }
         $createTable .= ' CONNECTION=\'mysql://' . $remoteLoginData['user'] . ':' . $remoteLoginData['password'] . '@' . $remoteLoginData['host'] . '/' . $remoteLoginData['database'] . '/' . $table . '\'';
         $slaveRepository->_sql('RENAME TABLE ' . $table . ' TO ' . $table . '_' . date('Ymd'), false);
         $slaveRepository->_sql($createTable);
         $slaveRepository->_sql('DROP TABLE ' . $table . '_' . date('Ymd') . ';');
         return true;
     }
     return false;
 }
 /**
  * Pushes a single table.
  *
  * @param Tx_Contentstage_Domain_Repository_Result $resource The db resource to get the data from.
  * @param Tx_Contentstage_Domain_Repository_ContentRepository $toRepository Repository to push to.
  */
 protected function pushTable(Tx_Contentstage_Domain_Repository_Result $resource, Tx_Contentstage_Domain_Repository_ContentRepository $toRepository)
 {
     $toRepository->insert($resource);
     $table = $resource->getTable();
     $tcaName = $this->tca->getTableName($table);
     $this->log->log($this->translate('info.push.table', array(empty($tcaName) || $table === $tcaName ? $table : '"' . $tcaName . '" (' . $table . ')', $resource->count())), $resource->count() > 0 ? Tx_CabagExtbase_Utility_Logging::OK : Tx_CabagExtbase_Utility_Logging::INFORMATION);
     $resource->free();
 }
 /**
  * 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;
 }
Example #4
0
 /**
  * Resolves the table => array of uids array.
  *
  * @param Tx_Contentstage_Domain_Repository_ContentRepository $repository The repository to get the data from.
  * @param array $uidsByTable The array with table => uids pairs.
  * @param string $returnField The field to return into the value.
  * @return string The string representation of the resolved field.
  */
 protected function resolveTables(Tx_Contentstage_Domain_Repository_ContentRepository $repository, &$uidsByTable, $returnField = null)
 {
     foreach ($uidsByTable as $table => &$uidData) {
         if (substr($table, 0, 2) === '__') {
             continue;
         }
         $labelField = $this->getLabelField($table) ?: 'uid';
         $resource = $repository->findInPageTree(0, $table, ($returnField !== null ? $returnField . ', ' : '') . $labelField, 'uid IN (' . implode(',', $uidData) . ')', '', 'uid ASC');
         $uidData = $resource->all($returnField ?: $labelField);
     }
 }