Skip to content

Instantly share code, notes, and snippets.

@georgringer
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgringer/831273dd08c28bce5f64 to your computer and use it in GitHub Desktop.
Save georgringer/831273dd08c28bce5f64 to your computer and use it in GitHub Desktop.
Command to migrate the import_id of tx_news_domain_model_news to the uid
<?php
namespace GeorgRinger\Theme\Command;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class UpdateCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
/**
* Change all news ids to the old ones
*/
public function migrateNewsIdsCommand() {
// Get import_id to the sys_category_mm table
$sql = 'UPDATE sys_category_record_mm mm
INNER JOIN tx_news_domain_model_news news
ON mm.uid_foreign = news.uid
SET mm.migration_id = news.import_id';
$this->getDatabaseConnection()->sql_query($sql);
$this->outputLine(sprintf('Set migration_id to sys_category_record_mm, %s rows affected!', $this->getDatabaseConnection()->sql_affected_rows()));
// Get import_id to the sys_file_reference table
$sql = 'UPDATE sys_file_reference ref
INNER JOIN tx_news_domain_model_news news
ON ref.uid_foreign = news.uid
SET ref.migration_id = news.import_id';
$this->getDatabaseConnection()->sql_query($sql);
$this->outputLine(sprintf('Set migration_id to sys_file_reference, %s rows affected!', $this->getDatabaseConnection()->sql_affected_rows()));
// copy ids in sys_category
$sql = 'UPDATE sys_category_record_mm
SET uid_foreign = migration_id WHERE tablenames="tx_news_domain_model_news" AND fieldname="categories"';
$this->getDatabaseConnection()->sql_query($sql);
$this->outputLine('Swapped ids in sys_category_record_mm');
// copy ids in sys_category
$sql = 'UPDATE sys_file_reference
SET uid_foreign = migration_id WHERE tablenames="tx_news_domain_model_news" AND fieldname="fal_media"';
$this->getDatabaseConnection()->sql_query($sql);
$this->outputLine('Swapped ids in sys_file_reference');
// Change ids to an unused id
$sql = ' UPDATE `tx_news_domain_model_news` SET `uid` = CONCAT(\'20000\', `uid`);';
$this->getDatabaseConnection()->sql_query($sql);
// copy ids in tx_news_domain_model_news
$sql = 'UPDATE tx_news_domain_model_news
SET uid = import_id WHERE import_id !=""';
$this->getDatabaseConnection()->sql_query($sql);
$this->outputLine('Swapped ids in tx_news_domain_model_news');
$this->outputLine('');
$this->outputLine('IMPORTANT: DO NOT RUN THIS CALL TWICE!!!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment