Anybody have a schema converter to convert back to OLD format

2 posts by 1 authors in: Forums > CMS Builder
Last Post: May 22, 2014   (RSS)

In case anyone else needs this, I think this seemed to work well:

<?php
function write_php_ini($array, $file)
{
    $res = array();
    $res[] = ";<?php die('This is not a program file.'); exit; ?>";
    $res[] = '';
    foreach($array as $key => $val)
    {
        if(is_array($val))
        {
            $res[] = "";
            $res[] = "[$key]";
            foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.$sval.'"');
        }
        else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
    }
    safefilerewrite($file, implode("\n", $res));
}

//////
function safefilerewrite($fileName, $dataToSave)
{    if ($fp = fopen($fileName, 'w'))
    {
        $startTime = microtime();
        do
        {            $canWrite = flock($fp, LOCK_EX);
           // If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
           if(!$canWrite) usleep(round(rand(0, 100)*1000));
        } while ((!$canWrite)and((microtime()-$startTime) < 1000));

        //file was locked so now we can store information
        if ($canWrite)
        {            fwrite($fp, $dataToSave);
            flock($fp, LOCK_UN);
        }
        fclose($fp);
    }

}

$LOADSTRUCT=true;
$file = "/home/ACCOUNT/public_html/cmsAdmin/data/schema/{$_GET['file']}";
$outfile = "/home/ACCOUNT/public_html/cmsAdmin/data/schema/new_{$_GET['file']}";

//requires that you KNOW the current file is in schema format rather than INI format
$struct = include($file);

//Dump the schema so we can tell that we read it correctly
print_r($struct);

//Write in INI format
write_php_ini($struct,$outfile);
?>