An error occurred while loading the file. Please try again.
-
Patrick Barroca authoredddd21346
migrate_all_urls.php 1.66 KiB
<?php
require_once './console.php';
class Article_Url_Migrator {
use Trait_MemoryCleaner;
public function run() {
echo "\nStarted at " . date('c') . "\n";
$current = 0;
$total = Class_Article::count();
$count = 0;
while($models = Class_Article::findAllBy(['order' => 'id_article',
'limitPage' => [$current, 1000]])) {
$this->_runPage($models);
$count += count($models);
echo $count . '/'. $total . "\n";
$this->_cleanMemory();
$current++;
}
echo "\nFinished at " . date('c') . "\n";
}
protected function _runPage($models) {
foreach($models as $model)
$this->_runModel($model);
}
protected function _runModel($model) {
$model
->setDescription($this->_migrateAll($model->getDescription()))
->setContenu($this->_migrateAll($model->getContenu()))
->save()
;
}
protected function _migrateAll($data) {
foreach(['uploads\/' => '/userfiles/image/typo3images/uploads',
'fileadmin\/fichiers\/' => '/userfiles/image/typo3images/fileadmin/fichiers/',
'fileadmin\/user_upload\/' => '/userfiles/image/typo3images/fileadmin/user_upload/',
'typo3temp\/' => '/userfiles/image/typo3images/typo3temp/']
as $pattern => $replacement)
$data = $this->_migrate($data, $pattern, $replacement);
return $data;
}
protected function _migrate($data, $pattern, $replacement) {
$regs = '/(< *(a|img)[^>]*(href|src) *= *["\'])(http:\/\/[^"\']*\/)?' . $pattern . '([^"\']*)/i';
return preg_replace($regs, '$1'.$replacement.'$5', $data);
}
}
(new Article_Url_Migrator())->run();