diff --git a/.github/workflows/build-release/JsonCoreImage.php b/.github/workflows/build-release/JsonCoreImage.php index fa2729617..77d313279 100644 --- a/.github/workflows/build-release/JsonCoreImage.php +++ b/.github/workflows/build-release/JsonCoreImage.php @@ -13,12 +13,20 @@ require_once("CoreImage.php"); class JsonCoreImage extends CoreImage { - private $checksums = []; + protected $checksums = []; public function __construct($exportFolder, $tempFolder, $currentVersion, $imageFile) { $this->create_image($exportFolder, $tempFolder, $currentVersion); + $this->saveImage($imageFile); + } + + /** + * @param $imageFile + */ + protected function saveImage($imageFile) + { $json_result = json_encode($this->checksums, JSON_PRETTY_PRINT); $json_string_result = var_export($json_result, true); $data = $this->generateStub(); diff --git a/.github/workflows/build-release/JsonPharCoreImage.php b/.github/workflows/build-release/JsonPharCoreImage.php new file mode 100644 index 000000000..ac3dcce9a --- /dev/null +++ b/.github/workflows/build-release/JsonPharCoreImage.php @@ -0,0 +1,41 @@ +checksums); + + $imageJsonFile = "$imageFile.json"; + $fp = fopen($imageJsonFile, 'w'); + fwrite($fp, $json_result); + fclose($fp); + + $phar->startBuffering(); + $phar->setStub($this->generateStub()); + $phar->addFile($imageJsonFile, "core_image.json"); + $phar->compressFiles(Phar::GZ); + $phar->stopBuffering(); + rename($imagePharFile, $imageFile); + } + + protected function generateStub() + { + $data = parent::generateStub(); + $data .= "__HALT_COMPILER();"; + + return $data; + } +} \ No newline at end of file diff --git a/.github/workflows/build-release/e107_make.php b/.github/workflows/build-release/e107_make.php index b6f8f39d6..44a32716a 100644 --- a/.github/workflows/build-release/e107_make.php +++ b/.github/workflows/build-release/e107_make.php @@ -9,7 +9,7 @@ */ require_once("OsHelper.php"); -require_once("JsonCoreImage.php"); +require_once("JsonPharCoreImage.php"); $builder = new e107Build(); $builder->makeBuild(); @@ -505,7 +505,7 @@ class e107Build $imageFile = $this->tempDir . "core_image.php"; $this->status("Creating new core_image.php file ({$imageFile})", true); - new JsonCoreImage($this->exportDir, $this->tempDir, $this->version, $imageFile); + new JsonPharCoreImage($this->exportDir, $this->tempDir, $this->version, $imageFile); $dir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export"; $this->changeDir($dir); diff --git a/e107_admin/core_image.php b/e107_admin/core_image.php index 415331344..3b319d750 100644 Binary files a/e107_admin/core_image.php and b/e107_admin/core_image.php differ diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 054aa984b..082417350 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -193,7 +193,7 @@ class e107 'e_bb_base' => '{e_HANDLER}bbcode_handler.php', 'e_customfields' => '{e_HANDLER}e_customfields_class.php', 'e_file' => '{e_HANDLER}file_class.php', - 'e_file_inspector' => '{e_HANDLER}e_file_inspector_json.php', + 'e_file_inspector' => '{e_HANDLER}e_file_inspector_json_phar.php', 'e_form' => '{e_HANDLER}form_handler.php', 'e_jshelper' => '{e_HANDLER}js_helper.php', 'e_media' => '{e_HANDLER}media_class.php', diff --git a/e107_handlers/e_file_inspector_json.php b/e107_handlers/e_file_inspector_json.php index 4d1448416..1cc65aec0 100644 --- a/e107_handlers/e_file_inspector_json.php +++ b/e107_handlers/e_file_inspector_json.php @@ -11,7 +11,7 @@ require_once("e_file_inspector.php"); class e_file_inspector_json extends e_file_inspector { - private $coreImage; + protected $coreImage; /** * @param $jsonFilePath string Absolute path to the file inspector database @@ -72,7 +72,7 @@ class e_file_inspector_json extends e_file_inspector * @copyright Copyright (c) Taylor Otwell * @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License */ - private static function array_slash($array, $prepend = '') + protected static function array_slash($array, $prepend = '') { $results = array(); diff --git a/e107_handlers/e_file_inspector_json_phar.php b/e107_handlers/e_file_inspector_json_phar.php new file mode 100644 index 000000000..142a60b84 --- /dev/null +++ b/e107_handlers/e_file_inspector_json_phar.php @@ -0,0 +1,53 @@ +database, "core_image.phar"); + $tmpFile = tmpfile(); + $tmpFilePath = stream_get_meta_data($tmpFile)['uri']; + $this->copyUrlToResource("phar://core_image.phar/core_image.json", $tmpFile); + $this->coreImage = json_decode(file_get_contents($tmpFilePath), true); + if (!is_array($this->coreImage)) $this->coreImage = []; + $this->coreImage = self::array_slash($this->coreImage); + if (!$this->coreImage) $this->coreImage = []; + } + + /** + * Copy file to destination with low memory footprint + * @param $source string URL of the source + * @param $destination resource File pointer of the destination + */ + private function copyUrlToResource($source, $destination) + { + $dbFile = fopen($source, "r"); + while (!feof($dbFile)) + { + $buffer = fread($dbFile, 4096); + fwrite($destination, $buffer); + } + unset($buffer); + fclose($dbFile); + } +} \ No newline at end of file diff --git a/e107_handlers/e_file_inspector_sqlphar.php b/e107_handlers/e_file_inspector_sqlphar.php index 85b68e474..5bc33ff46 100644 --- a/e107_handlers/e_file_inspector_sqlphar.php +++ b/e107_handlers/e_file_inspector_sqlphar.php @@ -89,7 +89,6 @@ class e_file_inspector_sqlphar extends e_file_inspector return $this->currentVersion = $statement->fetchColumn(); } - /** * Copy file to destination with low memory footprint * @param $source string URL of the source diff --git a/e107_tests/tests/unit/e_file_inspectorTest.php b/e107_tests/tests/unit/e_file_inspectorTest.php index a5a806d2f..52ed9a0e0 100644 --- a/e107_tests/tests/unit/e_file_inspectorTest.php +++ b/e107_tests/tests/unit/e_file_inspectorTest.php @@ -16,9 +16,9 @@ class e_file_inspectorTest extends \Codeception\Test\Unit public function _before() { - require_once(e_HANDLER . "e_file_inspector_json.php"); - require_once(e_HANDLER . "e_file_inspector_sqlphar.php"); - $this->e_integrity = new e_file_inspector_json(); + require_once(e_HANDLER . "e_file_inspector_json_phar.php"); + // TODO: Make test databases; don't hard-code e107_admin/core_image.php and hope it has the expected content. + $this->e_integrity = new e_file_inspector_json_phar(e_ADMIN . "core_image.php"); } public function testGetChecksums()