Skip to content

Instantly share code, notes, and snippets.

@Gerhard-Kanzler
Last active October 8, 2024 08:06
Show Gist options
  • Select an option

  • Save Gerhard-Kanzler/6a0399dea5006bd3f7e653d94a8fb8ba to your computer and use it in GitHub Desktop.

Select an option

Save Gerhard-Kanzler/6a0399dea5006bd3f7e653d94a8fb8ba to your computer and use it in GitHub Desktop.
Pimcore 6 to Pimcore 10 Helper
<?php
/**
* 9 Juni 2021 by Gerhard Kanzler
**/
include "./vendor/autoload.php";
function renameYmlToYaml( DirectoryIterator $dir ){
$data = [];
foreach( $dir as $node ){
if( $node->isDir() && !$node->isDot() ){
renameYmlToYaml( new DirectoryIterator( $node->getPathname() ) );
}else{
if( $node->isFile() ){
if( strpos( $node->getFilename(), '.yml' ) !== false ){
$newName = str_replace( '.yml', '.yaml', $node->getPathname() );
rename( $node->getPathname(), $newName );
echo " - " . $node->getPathname() . " -> " . $newName . "\n";
}
$data[ $node->getPathname() ] = $node->getFilename();
}
}
}
}
echo "-- START --\n";
if( is_dir( './app/config' ) ){
echo "-- Move /app/config to /config --\n";
shell_exec( 'mv ./app/config ./' );
}else{
echo "-- /app/config already moved --\n";
}
echo "-- Rename .yml to .yaml --\n";
if( is_dir( './config' ) ){
//$configFolder = dirToArray('./config');
renameYmlToYaml( new DirectoryIterator( './config' ) );
echo "-- Move config_dev.yaml config_prod.yaml config_text.yaml --\n";
if( !is_dir( './config/packages' ) ){
echo " - create folder ./config/packages\n";
shell_exec( 'mkdir ./config/packages' );
}
foreach( [ 'dev', 'test', 'prod' ] as $suffix ){
if( !is_dir( './config/packages/' . $suffix ) ){
echo " - create folder ./config/packages/" . $suffix . "\n";
shell_exec( 'mkdir ./config/packages/' . $suffix );
}
$filename = './config/config_' . $suffix . '.yaml';
if( file_exists( $filename ) ){
echo " - move/rename: " . $filename . "-> ./config/packages/" . $suffix . "/config.yaml\n";
rename( $filename, './config/packages/' . $suffix . '/config.yaml' );
}
}
echo "-- update include path in packages/.../config.yaml\n";
foreach( [ 'dev', 'test', 'prod' ] as $suffix ){
$filename = './config/packages/' . $suffix . '/config.yaml';
$file = file_get_contents( $filename );
$file = preg_replace( '/\s(config.yml)/', ' ../../config.yaml', $file );
file_put_contents( $filename, $file );
echo " - " . $filename . " updated\n";
}
echo "-- update config.yaml --\n";
if( file_exists('./config/config.yml') ){
$configFile = file_get_contents( './config/config.yml' );
$content = preg_replace( '/\s+-\s{\s(resource)\:\s(security.yaml)\s\}/', '', $configFile );
file_put_contents( './config/config.yaml', $content );
}
echo "-- update parameters.yaml --\n";
}
if( !is_dir( './config/routes' ) ){
echo "-- Creates ./config/routes --\n";
shell_exec( 'mkdir ./config/routes' );
}
if( !is_dir( './config/routes/dev' ) ){
echo "-- Creates ./config/routes/dev --\n";
shell_exec( 'mkdir ./config/routes/dev' );
}
if( file_exists( './config/routing.yaml' ) ){
echo "-- rename routing.yaml -> routes.yaml\n";
rename( './config/routing.yaml', './config/routes.yaml' );
}
if( file_exists( './config/routing_dev.yaml' ) ){
echo "-- rename and move routing_dev.yaml -> /routes/dev/routes.yaml\n";
rename( './config/routing_dev.yaml', './config/routes/dev/routes.yaml' );
}
if( file_exists( './config/security.yaml' ) ){
echo "-- move security.yaml -> /packages/security.bak\n";
rename( './config/security.yaml', './config/packages/security.bak' );
echo "-- create security.yaml from v10.0.0 skeleton\n";
$content = file_get_contents('https://raw.githubusercontent.com/pimcore/skeleton/v10.0.0/config/packages/security.yaml');
file_put_contents('./config/packages/security.yaml', $content);
}
if( !file_exists( './config/bundles.php' ) ){
echo "-- create bundles.php\n";
file_put_contents( './config/bundles.php', '<?php
return [
//Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => [\'all\' => true],
];' );
}
if( !file_exists( './config/preload.php' ) ){
echo "-- create preload.php\n";
file_put_contents( './config/preload.php', '<?php
if (file_exists(dirname(__DIR__).\'/var/cache/prod/App_KernelProdContainer.preload.php\')) {
require dirname(__DIR__).\'/var/cache/prod/App_KernelProdContainer.preload.php\';
}' );
}
if( !is_dir( './public' ) ){
echo "-- move web/bundles -> public/bundles\n";
shell_exec( 'mv ./web ./public' );
}
if( !file_exists( './public/index.php' ) ){
echo "-- create index.php\n";
$content = file_get_contents('https://raw.githubusercontent.com/pimcore/skeleton/v10.0.0/public/index.php');
file_put_contents('./public/index.php', $content);
}
if( file_exists( './public/app.php' ) ){
echo "-- remove app.php\n";
unlink( './public/app.php' );
}
if( file_exists( './public/.htaccess' ) ){
echo "-- change app.php -> index.php in .htaccess\n";
$content = file_get_contents('./public/.htaccess');
$content = str_replace('app.php', 'index.php', $content);
file_put_contents( './public/.htaccess', $content );
}
if( is_dir('./app/Resources/views') ){
echo "-- move ./app/Resources/views -> ./templates\n";
shell_exec('mv ./app/Resources/views ./templates');
}
if( file_exists('./app/AppKernel.php') ){
echo "-- move AppKernel.php\n";
shell_exec('mv ./app/AppKernel.php ./src/Kernel.php');
echo "-- change Namespace from Kernel.php\n";
$content = file_get_contents('./src/Kernel.php');
file_put_contents( './src/Kernel.php', str_replace([
'<?php',
'class AppKernel extends Kernel',
'use Pimcore\Kernel;'
], [
'<?php
namespace App;
',
'use Pimcore\Kernel as PimcoreKernel;
class Kernel extends PimcoreKernel',
''], $content) );
}
if( !file_exists('.env') ){
echo "-- create .env file\n";
$envContent = file_get_contents('https://raw.githubusercontent.com/pimcore/skeleton/v10.0.0/.env');
file_put_contents('.env', $envContent);
}
if(file_exists('./var/config/system.yml')) {
echo "-- check system.yml --\n";
$yaml = \Symfony\Component\Yaml\Yaml::parse(file_get_contents('./var/config/system.yml'));
if( array_key_exists('swiftmailer', $yaml) ){
unset($yaml['swiftmailer']);
echo " -- unset swiftmailer\n";
}
if( array_key_exists('webservice', $yaml['pimcore']) ){
unset($yaml['pimcore']['webservice']);
echo " -- unset webservice\n";
}
if( array_key_exists('show_cookie_notice', $yaml['pimcore']['general']) ){
unset($yaml['pimcore']['general']['show_cookie_notice']);
echo " -- unset show_cookie_notice\n";
}
if( array_key_exists('method', $yaml['pimcore']['email']) ){
unset($yaml['pimcore']['email']['method']);
echo " -- unset email->method\n";
}
if( array_key_exists('cache', $yaml['pimcore']) ){
$yaml['pimcore']['full_page_cache'] = $yaml['pimcore']['cache'];
unset($yaml['pimcore']['cache']);
echo " -- rename cache -> full_page_cache\n";
}
file_put_contents( './var/config/system.yml', \Symfony\Component\Yaml\Yaml::dump($yaml, 5) );
}
if( is_dir('./var/recyclebin') ){
echo "-- remove recyclebin folder\n";
shell_exec('rm -r ./var/recyclebin');
}
if( is_dir('./var/tmp') ){
echo "-- remove /var/tmp folder\n";
shell_exec('rm -r ./var/tmp');
}
if( is_dir('./public/var/tmp') ){
echo "-- remove /public/var/tmp folder\n";
shell_exec('rm -r ./public/var/tmp');
}
if( !is_dir('./var/admin') ){
echo "-- create ./var/admin folder\n";
shell_exec('mkdir ./var/admin');
if( is_dir('./var/user-image') ){
echo "-- create ./var/admin folder\n";
shell_exec('mv ./var/user-image ./var/admin/user-image');
}
}
if( file_exists('./config/local/database.yaml') ){
$dbConfigYml = \Symfony\Component\Yaml\Yaml::parse(file_get_contents('./config/local/database.yaml'));
if( !array_key_exists( 'mapping_types', $dbConfigYml['doctrine']['dbal']['connections']['default'] ) ){
echo "-- add mapping_types to database.yaml\n";
$dbConfigYml['doctrine']['dbal']['connections']['default']['mapping_types'] = [
'enum' => 'string',
'bit' => 'boolean'
];
file_put_contents( './config/local/database.yaml', \Symfony\Component\Yaml\Yaml::dump($dbConfigYml, 5) );
}
}
echo "\n";
echo "\n";
echo "\n";
echo "----------------------------\n";
echo "MANUELLER Prozess!\n";
echo "WICHTIG:\n";
echo "https://github.com/pimcore/skeleton/blob/10.x/config\n";
echo "Bitte files Kontrollieren!\n";
echo "\n";
echo "security.bak mit security.yaml manuell zusammenführe!\n";
echo "----------------------------\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment