Skip to content
Snippets Groups Projects
migrateModulesConfig.php 1.65 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    require '../../vendor/autoload.php';
    
    chdir('../..');
    
    $nonReadableFiles = [];
    $migrated = 0;
    $customs =  scandir('custom');
    
    foreach ($customs as $custom) {
    
        if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) {
    
            continue;
        }
    
        \SrcCore\models\DatabasePDO::reset();
        new \SrcCore\models\DatabasePDO(['customId' => $custom]);
    
        $path = "custom/{$custom}/apps/maarch_entreprise/xml/config.xml";
        if (file_exists($path)) {
            if (!is_readable($path) || !is_writable($path)) {
                $nonReadableFiles[] = $path;
                continue;
            }
            $loadedXml = simplexml_load_file($path);
            
            if ($loadedXml) {
    
                $loadedXml->CONFIG->CookieTime = 10080;
    
                $i = 0;
                foreach ($loadedXml->MODULES as $value) {
                    if (in_array($loadedXml->MODULES[$i]->moduleid, ['convert', 'reports', 'full_text', 'cases'])) {
                        unset($loadedXml->MODULES[$i]);
                    }
                    $i++;
                }
    
                $res = formatXml($loadedXml);
                $fp = fopen($path, "w+");
                if ($fp) {
                    fwrite($fp, $res);
                }
    
                $migrated++;
            }
        }
    }
    
    foreach ($nonReadableFiles as $file) {
        printf("The file %s it is not readable or not writable.\n", $file);
    }
    
    printf($migrated . " custom(s) avec config.xml (modules) trouvé(s) et migré(s).\n");
    
    function formatXml($simpleXMLElement)
    {
        $xmlDocument = new DOMDocument('1.0');
        $xmlDocument->preserveWhiteSpace = false;
        $xmlDocument->formatOutput = true;
        $xmlDocument->loadXML($simpleXMLElement->asXML());
    
        return $xmlDocument->saveXML();
    }