HTML/FlexyFramework/Generator.php
[pear] / HTML / FlexyFramework / Generator.php
index 3bd42a4..f868088 100644 (file)
@@ -11,7 +11,7 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
     
     function generateClasses()
     {
-        //echo "GENERATE CLASSES?";
+//        echo "GENERATE CLASSES?";
         if (!HTML_FlexyFramework_Generator::$generateClasses ) {
             return;
         }
@@ -173,6 +173,9 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
     static function writeCache($iniCacheTmp, $iniCache)
     {
         
+        $fp = fopen($iniCache.".lock", "a+");
+        flock($fp,LOCK_EX);
+
         $ff = HTML_FlexyFramework::get();
         $ff->debug('Framework Generator:writeCache ' . $iniCacheTmp .  ' ' . $iniCache);
           
@@ -202,31 +205,43 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
         $linksCacheTmp = preg_replace('/\.ini/', '.links.ini', $iniCacheTmp );
         $links = array();
         if (file_exists($linksCacheTmp )) {
-            $links = self::mergeIni( parse_ini_file($linksCacheTmp, true), $links);   
+            $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).'/*.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);
             }
+            
+            // 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);   
         }
@@ -242,12 +257,18 @@ class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
         if (count($out)) {
             $ff->debug("Writing merged Links file : $iniLinksCache \n");
 
-            file_put_contents($iniLinksCache. '.tmp', implode("\n", $out));
-            if (file_exists($iniLinksCache)) {
+           
+            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($iniCache.".lock");
+        
     }
     /* bit like merge recursive, but it avoids doing stuff with arrays.. */
     static function mergeIni($new, $old)