mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-03 23:34:01 +01:00
Invalidate OP cache before getting file contents
This commit is contained in:
@@ -351,7 +351,7 @@ class File
|
||||
}
|
||||
|
||||
public function writeFile() {
|
||||
global $file, $t, $ICEcoder, $serverType, $doNext, $contents;
|
||||
global $file, $t, $ICEcoder, $serverType, $doNext, $contents, $systemClass;
|
||||
if (isset($_POST['changes'])) {
|
||||
// Get existing file contents as lines and stitch changes onto it
|
||||
$fileLines = file($file);
|
||||
@@ -369,6 +369,7 @@ class File
|
||||
|
||||
// Newly created files have the perms set too
|
||||
$setPerms = (!file_exists($file)) ? true : false;
|
||||
$systemClass->invalidateOPCache($file);
|
||||
$fh = fopen($file, 'w') or die($t['Sorry, cannot save']);
|
||||
|
||||
// replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
|
||||
@@ -647,7 +648,7 @@ class File
|
||||
}
|
||||
|
||||
public function compileSass() {
|
||||
global $docRoot, $fileLoc, $fileName;
|
||||
global $docRoot, $fileLoc, $fileName, $systemClass;
|
||||
|
||||
$doNext = "";
|
||||
|
||||
@@ -667,6 +668,7 @@ class File
|
||||
|
||||
if (true === is_writable($docRoot . $fileLoc)) {
|
||||
$scssContent = $scss->compile('@import "' . $fileName . '"');
|
||||
$systemClass->invalidateOPCache($docRoot . $fileLoc . "/" . substr($fileName, 0, -4) . "css");
|
||||
$fh = fopen($docRoot . $fileLoc . "/" . substr($fileName, 0, -4) . "css", 'w');
|
||||
fwrite($fh, $scssContent);
|
||||
fclose($fh);
|
||||
|
||||
@@ -59,6 +59,16 @@ class System
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
public function invalidateOPCache($path): void
|
||||
{
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($path, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fileLines
|
||||
* @param $changes
|
||||
|
||||
@@ -44,6 +44,7 @@ if ("error" !== $result) {
|
||||
$lines = $maxLines + 1 + 1; // 1 (possibly) for end of file and 1 for partial lines
|
||||
|
||||
// Open the file
|
||||
$systemClass->invalidateOPCache($filename);
|
||||
$f = fopen($filename, "rb");
|
||||
|
||||
// Jump to last character
|
||||
|
||||
@@ -11,6 +11,7 @@ $prevIndexData = [];
|
||||
// If we have a data/index.php file
|
||||
if (file_exists($docRoot . $ICEcoderDir . "/data/index.php")) {
|
||||
// Get serialized array back out of PHP file inside a comment block as prevIndexData
|
||||
$systemClass->invalidateOPCache($docRoot . $ICEcoderDir . "/data/index.php");
|
||||
$prevIndexData = file_get_contents($docRoot . $ICEcoderDir . "/data/index.php");
|
||||
if (false !== strpos($prevIndexData, "<?php")) {
|
||||
$prevIndexData = str_replace("<?php\n/*\n\n", "", $prevIndexData);
|
||||
@@ -208,6 +209,7 @@ if (!isset($_GET['timestamp']) || !isset($prevIndexData["timestamps"]) || $_GET[
|
||||
// If we have a data/git-diff.php file
|
||||
if (file_exists($docRoot . $ICEcoderDir . "/data/git-diff.php")) {
|
||||
// Get serialized array back out of PHP file inside a comment block as git data for git diff display
|
||||
$systemClass->invalidateOPCache($docRoot . $ICEcoderDir . "/data/git-diff.php");
|
||||
$gitDiffData = file_get_contents($docRoot . $ICEcoderDir . "/data/git-diff.php");
|
||||
if (strpos($gitDiffData, "<?php") !== false) {
|
||||
$gitDiffData = str_replace("<?php\n/*\n\n", "", $gitDiffData);
|
||||
@@ -220,6 +222,7 @@ if (!isset($_GET['timestamp']) || !isset($prevIndexData["timestamps"]) || $_GET[
|
||||
// If we have a data/git-content.php file
|
||||
if (file_exists($docRoot . $ICEcoderDir . "/data/git-content.php")) {
|
||||
// Get serialized array back out of PHP file inside a comment block as git data for git content usage
|
||||
$systemClass->invalidateOPCache($docRoot . $ICEcoderDir . "/data/git-content.php");
|
||||
$gitContent = file_get_contents($docRoot . $ICEcoderDir . "/data/git-content.php");
|
||||
if (strpos($gitContent, "<?php") !== false) {
|
||||
$gitContent = str_replace("<?php\n/*\n\n", "", $gitContent);
|
||||
|
||||
@@ -83,7 +83,7 @@ function getUserIP() {
|
||||
|
||||
// Get data from a fopen or CURL connection
|
||||
function getData($url, $type='fopen', $dieMessage = false, $timeout = 60) {
|
||||
global $context;
|
||||
global $context, $systemClass;
|
||||
|
||||
// Request is to connect via CURL
|
||||
if ($type === "curl" && function_exists('curl_init')) {
|
||||
@@ -106,13 +106,15 @@ function getData($url, $type='fopen', $dieMessage = false, $timeout = 60) {
|
||||
'timeout' => $timeout // secs
|
||||
)
|
||||
));
|
||||
$systemClass->invalidateOPCache($url);
|
||||
$data = @file_get_contents($url, false, $context);
|
||||
if (!$data) {
|
||||
$data = @file_get_contents(str_replace("https:", "http:", $url), false, $context);
|
||||
}
|
||||
} elseif (file_exists($url)) {
|
||||
$data = file_get_contents($url);
|
||||
}
|
||||
$systemClass->invalidateOPCache($url);
|
||||
$data = file_get_contents($url);
|
||||
}
|
||||
// Return data or die with message
|
||||
if ($data) {
|
||||
return $data;
|
||||
@@ -127,9 +129,10 @@ function getData($url, $type='fopen', $dieMessage = false, $timeout = 60) {
|
||||
// Require a re-index dir/file data next time we index
|
||||
function requireReIndexNextTime() {
|
||||
// If we have a data/index.php file
|
||||
global $docRoot, $ICEcoderDir;
|
||||
global $docRoot, $ICEcoderDir, $systemClass;
|
||||
if (true === file_exists($docRoot . $ICEcoderDir . "/data/index.php")) {
|
||||
// Get serialized array back out of PHP file inside a comment block as prevIndexData
|
||||
$systemClass->invalidateOPCache($docRoot . $ICEcoderDir . "/data/index.php");
|
||||
$prevIndexData = file_get_contents($docRoot . $ICEcoderDir . "/data/index.php");
|
||||
if (strpos($prevIndexData, "<?php") !== false) {
|
||||
$prevIndexData = str_replace("<?php\n/*\n\n", "", $prevIndexData);
|
||||
@@ -351,7 +354,10 @@ function getVersionsCount($fileLoc, $fileName) {
|
||||
}
|
||||
|
||||
function serializedFileData($do, $path, $output=null) {
|
||||
global $systemClass;
|
||||
|
||||
if ($do === "get") {
|
||||
$systemClass->invalidateOPCache($path);
|
||||
$data = file_get_contents($path);
|
||||
$data = str_replace("<"."?php\n/*\n\n", "", $data);
|
||||
$data = str_replace("\n\n*/\n?".">", "", $data);
|
||||
|
||||
@@ -15,6 +15,7 @@ if (!$demoMode && true === isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']
|
||||
$fh = fopen("../data/" . $settingsFile, 'w');
|
||||
fwrite($fh, str_replace('"tutorialOnLogin" => true', '"tutorialOnLogin" => false', $settingsContents));
|
||||
fclose($fh);
|
||||
$ICEcoder['tutorialOnLogin'] = false;
|
||||
} else {
|
||||
echo "<script>parent.ICEcoder.message('" . $t['Cannot update config'] . " data/" . $settingsFile . " " . $t['and try again'] . "');</script>";
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ require_once dirname(__FILE__) . "/../classes/System.php";
|
||||
use ICEcoder\ExtraProcesses;
|
||||
|
||||
$settingsClass = new \ICEcoder\Settings();
|
||||
$systemClass = new \ICEcoder\System();
|
||||
|
||||
// Create a new config file if it doesn't exist yet.
|
||||
// The reason we create it, is so it has PHP write permissions, meaning we can update it later
|
||||
@@ -27,6 +28,7 @@ if (false === file_exists(dirname(__FILE__) . "/../data/" . $configSettings)) {
|
||||
}
|
||||
|
||||
// Load config settings
|
||||
$systemClass->invalidateOPCache(dirname(__FILE__) . "/../data/" . $configSettings);
|
||||
include dirname(__FILE__) . "/../data/" . $configSettings;
|
||||
|
||||
// Load common functions
|
||||
@@ -52,6 +54,7 @@ if (false === file_exists(dirname(__FILE__) . "/../data/" . $settingsFile) && $I
|
||||
}
|
||||
|
||||
// Load user settings
|
||||
$systemClass->invalidateOPCache(dirname(__FILE__) . "/../data/" . $settingsFile);
|
||||
include dirname(__FILE__) . "/../data/" . $settingsFile;
|
||||
|
||||
// Remove any previous files that are no longer there
|
||||
|
||||
@@ -11,6 +11,9 @@ function requireReIndexNextTime() {
|
||||
// If we have a data/index.php file
|
||||
if (file_exists(dirname(__FILE__)."/../data/index.php")) {
|
||||
// Get serialized array back out of PHP file inside a comment block as prevIndexData
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate(dirname(__FILE__)."/../data/index.php", true);
|
||||
}
|
||||
$prevIndexData = file_get_contents(dirname(__FILE__)."/../data/index.php");
|
||||
if (strpos($prevIndexData, "<?php") !== false) {
|
||||
$prevIndexData = str_replace("<?php\n/*\n\n", "", $prevIndexData);
|
||||
@@ -38,7 +41,6 @@ while(true) {
|
||||
$output = ["paths" => array_filter($diffLines)];
|
||||
// Store the serialized array in PHP comment block for pick up
|
||||
file_put_contents(dirname(__FILE__)."/../data/git-diff.php", "<?php\n/*\n\n".serialize($output)."\n\n*/\n?".">");
|
||||
|
||||
// Set Git contents
|
||||
$output = [];
|
||||
$paths = array_filter($diffLines);
|
||||
|
||||
Reference in New Issue
Block a user