Skip to content
Snippets Groups Projects
Commit 20a6fe97 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'master' into 'WIP'

add inject bokeh url php script

See merge request !2011
parents 4f4223e1 9e98ec5b
Branches
Tags
1 merge request!2011add inject bokeh url php script
Pipeline #378 passed with stage
in 23 minutes and 37 seconds
<?php
if(!isset($argv[1])) {
echo "\nFatal Error : Missing Bokeh folder name to inject.\n\n";
exit;
}
require_once 'console.php';
$injector = function($value) use($argv) {
if(false === strpos($value, '/userfiles/'))
return $value;
if (false === strpos($value, $argv[1]))
$value = str_replace('//', '/', '/' . $argv[1] . '/' . $value);
if ('//' == substr($value, 0, 2))
$value = substr($value, 1);
return $value;
};
// profils
echo "\nStarting inject : " . $argv[1];
echo "\n\nPhase profil\n";
foreach (Class_Profil::findAll() as $profile) {
echo '.';
$config = $profile->getCfgSiteAsArray();
$changed = false;
foreach(['header_img',
'favicon',
'logo_gauche_img',
'logo_droite_img',
'header_css',
'header_js',
'page_css'] as $name) {
if((!isset($config[$name])) || (!$config[$name]))
continue;
$old_value = $config[$name];
$config[$name] = $injector($old_value);
if($old_value != $config[$name])
$changed = true;
}
if ($changed)
$profile->setCfgSite($config)->save();
}
Class_Profil::clearCache();
//domains
echo "\n\nPhase domain\n";
foreach(Class_Catalogue::findAllBy(['where' => 'url_img like "%/userfiles/%"']) as $domain) {
echo '.';
$old_value = $domain->getUrlImg();
$new_url = $injector($old_value);
if($old_value != $new_url)
$domain->setUrlImg($new_url)->save();
}
Class_Catalogue::clearCache();
// articles
echo "\n\nPhase article\n";
$injector = function($value) use ($argv) {
$pattern = '/=(["\'])[^"\']*\/userfiles\/([^"\']*)/i';
return str_replace('/userfiles/userfiles/',
'/userfiles/',
preg_replace($pattern, '=$1/' . $argv[1] . '/userfiles/$2', $value));
};
foreach(Class_Article::findAllBy(['where' => 'concat(description,contenu) like "%/userfiles/%"'])
as $article) {
echo '.';
$article->setDescription($injector($article->getDescription()))
->setContenu($injector($article->getContenu()))
->save();
}
Class_Article::clearCache();
echo "\n\nInjection terminated\n";
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment