mirror of
https://github.com/processwire/processwire.git
synced 2025-08-29 01:20:25 +02:00
Attempt fix for issue processwire/processwire-issues#635 with FileCompiler and PHP touch() when PW run under different user accounts
This commit is contained in:
@@ -388,7 +388,7 @@ class FileCompiler extends Wire {
|
|||||||
$targetData = $this->compileData($targetData, $sourcePathname);
|
$targetData = $this->compileData($targetData, $sourcePathname);
|
||||||
if(false !== file_put_contents($targetPathname, $targetData, LOCK_EX)) {
|
if(false !== file_put_contents($targetPathname, $targetData, LOCK_EX)) {
|
||||||
$this->chmod($targetPathname);
|
$this->chmod($targetPathname);
|
||||||
touch($targetPathname, filemtime($sourcePathname));
|
$this->touch($targetPathname, filemtime($sourcePathname));
|
||||||
$targetHash = md5_file($targetPathname);
|
$targetHash = md5_file($targetPathname);
|
||||||
$cacheData = array(
|
$cacheData = array(
|
||||||
'source' => array(
|
'source' => array(
|
||||||
@@ -977,7 +977,7 @@ class FileCompiler extends Wire {
|
|||||||
|
|
||||||
copy($sourceFile, $targetFile);
|
copy($sourceFile, $targetFile);
|
||||||
$this->chmod($targetFile);
|
$this->chmod($targetFile);
|
||||||
touch($targetFile, filemtime($sourceFile));
|
$this->touch($targetFile, filemtime($sourceFile));
|
||||||
$numCopied++;
|
$numCopied++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1060,7 +1060,7 @@ class FileCompiler extends Wire {
|
|||||||
// maintenance already run today
|
// maintenance already run today
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
touch($lastRunFile);
|
$this->touch($lastRunFile);
|
||||||
$this->chmod($lastRunFile);
|
$this->chmod($lastRunFile);
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
|
|
||||||
@@ -1113,11 +1113,11 @@ class FileCompiler extends Wire {
|
|||||||
unlink($targetFile);
|
unlink($targetFile);
|
||||||
if($useLog) $this->log("Maintenance/Remove target file: $targetURL$basename");
|
if($useLog) $this->log("Maintenance/Remove target file: $targetURL$basename");
|
||||||
|
|
||||||
} else if(filemtime($sourceFile) != filemtime($targetFile)) {
|
} else if(filemtime($sourceFile) > filemtime($targetFile)) {
|
||||||
// source file has changed
|
// source file has changed
|
||||||
copy($sourceFile, $targetFile);
|
copy($sourceFile, $targetFile);
|
||||||
$this->chmod($targetFile);
|
$this->chmod($targetFile);
|
||||||
touch($targetFile, filemtime($sourceFile));
|
$this->touch($targetFile, filemtime($sourceFile));
|
||||||
if($useLog) $this->log("Maintenance/Copy new version of source file to target file: $sourceURL$basename => $targetURL$basename");
|
if($useLog) $this->log("Maintenance/Copy new version of source file to target file: $sourceURL$basename => $targetURL$basename");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1162,5 +1162,29 @@ class FileCompiler extends Wire {
|
|||||||
$this->exclusions[] = $pathname;
|
$this->exclusions[] = $pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as PHP touch() but with fallbacks for cases where touch() does not work
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param null|int $time
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function touch($filename, $time = null) {
|
||||||
|
if($time === null) {
|
||||||
|
$result = @touch($filename);
|
||||||
|
} else {
|
||||||
|
$result = @touch($filename, $time);
|
||||||
|
// try again, but without time
|
||||||
|
if(!$result) $result = @touch($filename);
|
||||||
|
}
|
||||||
|
if(!$result) {
|
||||||
|
// lastly try alternative method which should have same affect as touch without $time
|
||||||
|
$fp = fopen($filename, 'a');
|
||||||
|
$result = $fp !== false ? fclose($fp) : false;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user