function _configDataObjectsCache()
{
// cli works under different users... it may cause problems..
+
$this->debug(__METHOD__);
+
+ if ($this->database === false) {
+ return;
+ }
+
if (function_exists('posix_getpwuid')) {
$uinfo = posix_getpwuid( posix_getuid () );
$user = $uinfo['name'];
$iniCache = ini_get('session.save_path') .'/' .
- 'dbcfg-' . $user . '/'. str_replace('/', '_', $this->project) ;
+ 'dbcfg-' . $user . '/'. str_replace('/', '_', $this->project);
if ($this->appNameShort) {
if ($this->version) {
$iniCache .= '.' . $this->version;
}
- if ($this->database === false) {
- return;
- }
+
$dburl = parse_url($this->database);
if (!empty($dburl['path'])) {
$this->dataObjectsOriginalIni = $this->DB_DataObject[$dbini];
///print_r($this->DB_DataObject);exit;
}
- //
-
-
-
+
+
$this->DB_DataObject[$dbini] = $iniCache;
// we now have the configuration file name..
$iniCache = $this->DB_DataObject[$dbini];
$this->debug('generateDataobjectsCache:' .dirname($iniCache).'/*.ini');
- if ($force && file_exists($iniCache)) {
-
+
+ $replace = array();
+
+ if (file_exists($iniCache)) {
$files = glob(dirname($iniCache).'/*.ini');
foreach($files as $f) {
- unlink($f);
+ $replace[$f] = md5(file_get_contents($f)); // hash it..
+
}
- clearstatcache();
}
$this->debug('generateDataobjectsCache: DONE ini delete');
$generator->start();
$this->debug('generateDataobjectsCache: done generator');
- HTML_FlexyFramework_Generator::writeCache($iniCacheTmp, $iniCache);
+ HTML_FlexyFramework_Generator::writeCache($iniCacheTmp, $iniCache, $replace);
// reset the cache to the correct lcoation.
$this->DB_DataObject[$dbini] = $iniCache;
}
/**
* Generate the cached *.ini and links.ini files (merged for all components)
- *
+ * @param string $iniCacheTmp a temporary file
+ * @param string $iniCache the real target.
*/
- static function writeCache($iniCacheTmp, $iniCache)
+ static function writeCache($iniCacheTmp, $iniCache, $replace = array())
{
$fp = fopen($iniCache.".lock", "a+");
//var_dump($iniCacheTmp);
// echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
// only unpdate if nothing went wrong.
+ clearstatcace();
if (file_exists($iniCacheTmp) && filesize($iniCacheTmp)) {
- if (file_exists($iniCache)) {
- unlink($iniCache);
+ // is the replace file exist?
+ if (!isset($replace[$iniCache]) || $replace[$iniCache] != md5_file($iniCacheTmp)) {
+
+
+ if (file_exists($iniCache)) {
+ unlink($iniCache);
+ }
+ $ff->debug("Writing merged ini file : $iniCache\n");
+ rename($iniCacheTmp, $iniCache);
+ } else {
+ touch($iniCache);
}
- $ff->debug("Writing merged ini file : $iniCache\n");
- rename($iniCacheTmp, $iniCache);
}
-
+ /*
// readers..??? not needed??? (historical)
if (file_exists($iniCacheTmp.'.reader') && filesize($iniCacheTmp.'.reader')) {
if (file_exists($iniCache.'.reader')) {
$ff->debug("Writing merged reader file : $iniCache.reader\n");
rename($iniCacheTmp.'.reader', $iniCache.'.reader');
}
-
+ */
// merge and set links.. test for generated links file..
}
if (count($out)) {
$ff->debug("Writing merged Links file : $iniLinksCache \n");
-
-
- file_put_contents($iniCacheTmp. '.links.ini', implode("\n", $out));
- if (file_exists($iniLinksCache)) {
- unlink($iniLinksCache);
+ $out_str = implode("\n", $out);
+ // is target file different?
+ if (!isset($replace[$iniLinksCache]) || $replace[$iniLinksCache] != md5($out)) {
+
+ file_put_contents($iniCacheTmp. '.links.ini', $out_str);
+ if (file_exists($iniLinksCache)) {
+ unlink($iniLinksCache);
+ }
+ rename($iniCacheTmp. '.links.ini', $iniLinksCache);
+ } else {
+ touch($iniLinksCache);
+
}
- rename($iniCacheTmp. '.links.ini', $iniLinksCache);
}
flock($fp, LOCK_UN);
$iniCache = $this->PDO_DataObject['schema_location'];
- if ($force && file_exists($iniCache)) {
+
+ $replace = array();
+
+ if (file_exists($iniCache)) {
$files = glob(dirname($iniCache).'/*.ini');
foreach($files as $f) {
- unlink($f);
- }
- clearstatcache();
+ $replace[$f] = md5(file_get_contents($f)); // hash it..
+
+ }
}
+
+
$iniCacheTmp = $iniCache . '.tmp' .md5(rand()); // random to stop two processes using the same file.
// has it expired..
$force = ($force ? $force : !file_exists($iniCache)) || !$this->dataObjectsCacheExpires;
$generator->start();
$this->debug('generateDataobjectsCache', 'dataObjectsCache writing');
- HTML_FlexyFramework2_Generator::writeCache($iniCacheTmp, $iniCache);
+ HTML_FlexyFramework2_Generator::writeCache($iniCacheTmp, $iniCache, $replace);
// reset the cache to the correct lcoation.
PDO_DataObject::config('schema_location', $iniCache);
$this->PDO_DataObject['schema_location'] = $iniCache;
* Generate the cached *.ini and links.ini files (merged for all components)
*
*/
- static function writeCache($iniCacheTmp, $iniCache)
+ static function writeCache($iniCacheTmp, $iniCache, $replace = array())
{
$fp = fopen($iniCache.".lock", "a+");
// echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
// only unpdate if nothing went wrong.
if (file_exists($iniCacheTmp) && filesize($iniCacheTmp)) {
- if (file_exists($iniCache)) {
- unlink($iniCache);
+ // is the replace file exist?
+ if (!isset($replace[$iniCache]) || $replace[$iniCache] != md5_file($iniCacheTmp)) {
+
+
+ if (file_exists($iniCache)) {
+ unlink($iniCache);
+ }
+ $ff->debug("Writing merged ini file : $iniCache\n");
+ rename($iniCacheTmp, $iniCache);
+ } else {
+ touch($iniCache);
}
- $ff->debug("Writing merged ini file : $iniCache\n");
- rename($iniCacheTmp, $iniCache);
}
-
+ /*
// readers..??? not needed??? (historical)
if (file_exists($iniCacheTmp.'.reader') && filesize($iniCacheTmp.'.reader')) {
if (file_exists($iniCache.'.reader')) {
$ff->debug("Writing merged reader file : $iniCache.reader\n");
rename($iniCacheTmp.'.reader', $iniCache.'.reader');
}
-
+ */
// merge and set links.. test for generated links file..
}
if (count($out)) {
$ff->debug("Writing merged Links file : $iniLinksCache \n");
-
-
- file_put_contents($iniCacheTmp. '.links.ini', implode("\n", $out));
- if (file_exists($iniLinksCache)) {
- unlink($iniLinksCache);
+ $out_str = implode("\n", $out);
+ // is target file different?
+ if (!isset($replace[$iniLinksCache]) || $replace[$iniLinksCache] != md5($out)) {
+
+ file_put_contents($iniCacheTmp. '.links.ini', $out_str);
+ if (file_exists($iniLinksCache)) {
+ unlink($iniLinksCache);
+ }
+ rename($iniCacheTmp. '.links.ini', $iniLinksCache);
+ } else {
+ touch($iniLinksCache);
+
}
- rename($iniCacheTmp. '.links.ini', $iniLinksCache);
- }
+ } // we ignore that we might need to delete old links.ini
flock($fp, LOCK_UN);
fclose($fp);