function generateClasses()
{
- //echo "GENERATE CLASSES?";
+// echo "GENERATE CLASSES?";
if (!HTML_FlexyFramework_Generator::$generateClasses ) {
return;
}
- echo "GENERATE CLASSES?";
+
+ //echo "GENERATE CLASSES?";
parent::generateClasses();
}
file_put_contents($options["ini_{$this->_database}"] . '.reader', serialize($out));
}
+ /**
+ * Generate the cached readers used for meta data in the queries.
+ *
+ */
function _generateReader($table)
{
$DB = $this->getDatabaseConnection();
}
-
+ /**
+ * Generate the cached *.ini and links.ini files (merged for all components)
+ *
+ */
static function writeCache($iniCacheTmp, $iniCache)
{
-
- $ff = HTML_FlexyFramework::get();
- //var_dump($iniCacheTmp);
+ $fp = fopen($iniCache.".lock", "a+");
+ flock($fp,LOCK_EX);
+
+ $ff = HTML_FlexyFramework::get();
+ $ff->debug('Framework Generator:writeCache ' . $iniCacheTmp . ' ' . $iniCache);
+
+ //var_dump($iniCacheTmp);
// echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
// only unpdate if nothing went wrong.
- if (filesize($iniCacheTmp)) {
+ if (file_exists($iniCacheTmp) && filesize($iniCacheTmp)) {
if (file_exists($iniCache)) {
unlink($iniCache);
}
+ $ff->debug("Writing merged ini file : $iniCache\n");
rename($iniCacheTmp, $iniCache);
}
- // readers..
- if (filesize($iniCacheTmp.'.reader')) {
+ // readers..??? not needed??? (historical)
+ if (file_exists($iniCacheTmp.'.reader') && filesize($iniCacheTmp.'.reader')) {
if (file_exists($iniCache.'.reader')) {
unlink($iniCache.'.reader');
}
+ $ff->debug("Writing merged reader file : $iniCache.reader\n");
rename($iniCacheTmp.'.reader', $iniCache.'.reader');
}
- // merge and set links..
+ // merge and set links.. test for generated links file..
- $inis = explode(PATH_SEPARATOR,$ff->dataObjectsOriginalIni);
+ $linksCacheTmp = preg_replace('/\.ini/', '.links.ini', $iniCacheTmp );
$links = array();
- foreach($inis as $ini) {
- $ini = preg_replace('/\.ini$/', '.links.ini', $ini);
+ if (file_exists($linksCacheTmp )) {
+ $links = self::mergeIni( parse_ini_file($linksCacheTmp, true), $links);
+ unlink($linksCacheTmp);
+ }
+ // we are going to use the DataObject directories..
+
+ $inis = explode(PATH_SEPARATOR,$ff->DB_DataObject['class_location']);
+ //print_r($inis);exit;
+ $ff->debug("class_location = ". $ff->DB_DataObject['class_location']);
+
+ foreach($inis as $path) {
+ $ini = $path . '/'. strtolower( $ff->project) . '.links.ini';
+ //var_dump($ini);
if (!file_exists($ini)) {
+ $ff->debug("Framework Generator:writeCache PROJECT.links.ini does not exist in $path - trying glob");
+
// try scanning the directory for another ini file..
- $ar = glob(dirname($ini).'/*.ini');
+ $ar = glob(dirname($ini).'/*.links.ini');
+
+
if (empty($ar)) {
continue;
}
+
+
sort($ar);
+ $ff->debug("Framework Generator:writeCache using {$ar[0]}");
+
// first file.. = with links removed..
$ini = preg_replace('/\.links\./' , '.', $ar[0]);
$ini = preg_replace('/\.ini$/', '.links.ini', $ini);
}
- $links = array_merge_recursive($links , parse_ini_file($ini, true));
+ // why do this twice???
+ if (!file_exists($ini)) {
+ continue;
+ }
+ $ff->debug("Adding in $ini");
+ // prefer first ?
+ $links = self::mergeIni( parse_ini_file($ini, true), $links);
}
$iniLinksCache = preg_replace('/\.ini$/', '.links.ini', $iniCache);
$out = array();
$out[] = '';
}
if (count($out)) {
- file_put_contents($iniLinksCache. '.tmp', implode("\n", $out));
- if (file_exists($iniLinksCache)) {
+ $ff->debug("Writing merged Links file : $iniLinksCache \n");
+
+ $out = implode("\n", $out);
+
+
+ file_put_contents($iniCacheTmp. '.links.ini', implode("\n", $out));
+ if (file_exists($iniLinksCache)) {
unlink($iniLinksCache);
}
- rename($iniLinksCache. '.tmp', $iniLinksCache);
+ rename($iniCacheTmp. '.links.ini', $iniLinksCache);
}
+
+ flock($fp, LOCK_UN);
+ fclose($fp);
+ unlink($fp);
+
+ }
+ /* bit like merge recursive, but it avoids doing stuff with arrays.. */
+ static function mergeIni($new, $old)
+ {
+ foreach($new as $g => $ar) {
+ if (!isset($old[$g])) {
+ $old[$g] = $ar;
+ continue;
+ }
+ foreach($ar as $k=>$v) {
+ if (isset($old[$g][$k])) {
+ continue;
+ }
+ $old[$g][$k] = $v;
+ }
+ }
+ return $old;
+
+
}
-
}