mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
JSON reimplementation of CoreImage
This commit is contained in:
248
.github/workflows/build-release/CoreImage.php
vendored
248
.github/workflows/build-release/CoreImage.php
vendored
@@ -12,41 +12,15 @@ require_once("OsHelper.php");
|
|||||||
|
|
||||||
class CoreImage
|
class CoreImage
|
||||||
{
|
{
|
||||||
protected $coredir = [];
|
public function __construct($exportFolder, $currentVersion, $imageFile)
|
||||||
|
|
||||||
public function __construct($_current, $_deprecated, $_image)
|
|
||||||
{
|
{
|
||||||
set_time_limit(240);
|
set_time_limit(240);
|
||||||
|
|
||||||
$maindirs = array(
|
$this->create_image($exportFolder, $currentVersion, $imageFile);
|
||||||
'admin' => 'e107_admin/',
|
|
||||||
'files' => 'e107_files/',
|
|
||||||
'images' => 'e107_images/',
|
|
||||||
'themes' => 'e107_themes/',
|
|
||||||
'plugins' => 'e107_plugins/',
|
|
||||||
'handlers' => 'e107_handlers/',
|
|
||||||
'languages' => 'e107_languages/',
|
|
||||||
'downloads' => 'e107_files/downloads/',
|
|
||||||
'docs' => 'e107_docs/'
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($maindirs as $maindirs_key => $maindirs_value)
|
|
||||||
{
|
|
||||||
$this->coredir[$maindirs_key] = substr($maindirs_value, 0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->create_image($_current, $_deprecated, $_image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_image($_curdir, $_depdir, $_image)
|
function create_image($exportFolder, $currentVersion, $imageFile)
|
||||||
{
|
{
|
||||||
$search = $replace = [];
|
|
||||||
foreach ($this->coredir as $trim_key => $trim_dirs)
|
|
||||||
{
|
|
||||||
$search[$trim_key] = "'" . $trim_dirs . "'";
|
|
||||||
$replace[$trim_key] = "\$coredir['" . $trim_key . "']";
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = "<?php\n";
|
$data = "<?php\n";
|
||||||
$data .= "/*\n";
|
$data .= "/*\n";
|
||||||
$data .= "+ ----------------------------------------------------------------------------+\n";
|
$data .= "+ ----------------------------------------------------------------------------+\n";
|
||||||
@@ -65,39 +39,32 @@ class CoreImage
|
|||||||
$data .= "*/\n\n";
|
$data .= "*/\n\n";
|
||||||
$data .= "if (!defined('e107_INIT')) { exit; }\n\n";
|
$data .= "if (!defined('e107_INIT')) { exit; }\n\n";
|
||||||
|
|
||||||
$scan_current = $this->scan($_curdir);
|
echo("[Core-Image] Scanning Dir: " . $exportFolder . "\n");
|
||||||
|
$carry = $this->generateCurrentChecksums($exportFolder, $currentVersion);
|
||||||
|
|
||||||
|
echo("[Core-Image] Scanning Removed Files from Git" . "\n");
|
||||||
|
$result = $this->generateRemovedChecksums($carry);
|
||||||
|
|
||||||
echo("[Core-Image] Scanning Dir: " . $_curdir . "\n");
|
$json_result = json_encode($result, JSON_PRETTY_PRINT);
|
||||||
|
$json_string_result = var_export($json_result, true);
|
||||||
|
$data .= '$core_image = ' . $json_string_result . ';';
|
||||||
|
|
||||||
|
$fp = fopen($imageFile, 'w');
|
||||||
$image_array = var_export($scan_current, true);
|
|
||||||
$image_array = str_replace($search, $replace, $image_array);
|
|
||||||
$data .= "\$core_image = " . $image_array . ";\n\n";
|
|
||||||
|
|
||||||
$scan_deprecated = $this->generateRemovedChecksums();
|
|
||||||
$image_array = var_export($scan_deprecated, true);
|
|
||||||
$image_array = str_replace($search, $replace, $image_array);
|
|
||||||
$data .= "\$deprecated_image = " . $image_array . ";\n\n";
|
|
||||||
$data .= "?>";
|
|
||||||
|
|
||||||
$fp = fopen($_image, 'w');
|
|
||||||
fwrite($fp, $data);
|
fwrite($fp, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function scan($dir)
|
protected function generateCurrentChecksums($exportFolder, $currentVersion)
|
||||||
{
|
{
|
||||||
$absoluteBase = realpath($dir);
|
$absoluteBase = realpath($exportFolder);
|
||||||
if (!is_dir($absoluteBase)) return false;
|
if (!is_dir($absoluteBase)) return false;
|
||||||
|
|
||||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($exportFolder));
|
||||||
$files = [];
|
$checksums = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $file DirectoryIterator
|
* @var $file DirectoryIterator
|
||||||
*/
|
*/
|
||||||
foreach ($iterator as $file)
|
foreach ($iterator as $file) {
|
||||||
{
|
|
||||||
if ($file->isDir()) continue;
|
if ($file->isDir()) continue;
|
||||||
|
|
||||||
$absolutePath = $file->getRealPath();
|
$absolutePath = $file->getRealPath();
|
||||||
@@ -105,55 +72,15 @@ class CoreImage
|
|||||||
|
|
||||||
if (empty($relativePath) || $relativePath == $absolutePath) continue;
|
if (empty($relativePath) || $relativePath == $absolutePath) continue;
|
||||||
|
|
||||||
self::array_set($files, $relativePath, $this->checksumPath($absolutePath));
|
$checksum = $this->checksumPath($absolutePath);
|
||||||
|
$item = self::array_get($checksums, $relativePath, []);
|
||||||
|
if (!in_array($checksum, $item)) $item["v{$currentVersion}"] = $checksum;
|
||||||
|
self::array_set($checksums, $relativePath, $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($files);
|
ksort($checksums);
|
||||||
|
|
||||||
return $files;
|
return $checksums;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set an array item to a given value using "slash" notation.
|
|
||||||
*
|
|
||||||
* If no key is given to the method, the entire array will be replaced.
|
|
||||||
*
|
|
||||||
* Based on Illuminate\Support\Arr::set()
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
* @param string|null $key
|
|
||||||
* @param mixed $value
|
|
||||||
* @return array
|
|
||||||
* @copyright Copyright (c) Taylor Otwell
|
|
||||||
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
|
||||||
*/
|
|
||||||
private static function array_set(&$array, $key, $value)
|
|
||||||
{
|
|
||||||
if (is_null($key))
|
|
||||||
{
|
|
||||||
return $array = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$keys = explode('/', $key);
|
|
||||||
|
|
||||||
while (count($keys) > 1)
|
|
||||||
{
|
|
||||||
$key = array_shift($keys);
|
|
||||||
|
|
||||||
// If the key doesn't exist at this depth, we will just create an empty array
|
|
||||||
// to hold the next value, allowing us to create the arrays to hold final
|
|
||||||
// values at the correct depth. Then we'll keep digging into the array.
|
|
||||||
if (!isset($array[$key]) || !is_array($array[$key]))
|
|
||||||
{
|
|
||||||
$array[$key] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$array = &$array[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
$array[array_shift($keys)] = $value;
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checksumPath($filename)
|
protected function checksumPath($filename)
|
||||||
@@ -166,51 +93,6 @@ class CoreImage
|
|||||||
return md5(str_replace(array(chr(13), chr(10)), '', $body));
|
return md5(str_replace(array(chr(13), chr(10)), '', $body));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateRemovedChecksums()
|
|
||||||
{
|
|
||||||
$checksums = [];
|
|
||||||
|
|
||||||
$stdout = '';
|
|
||||||
OsHelper::runValidated('git tag --list ' . escapeshellarg("v*"), $stdout);
|
|
||||||
$tags = explode("\n", trim($stdout));
|
|
||||||
$versions = [];
|
|
||||||
foreach ($tags as $tag)
|
|
||||||
{
|
|
||||||
$versions[] = preg_replace("/^v/", "", $tag);
|
|
||||||
}
|
|
||||||
$tags = array_combine($tags, $versions);
|
|
||||||
unset($versions);
|
|
||||||
uasort($tags, function ($a, $b)
|
|
||||||
{
|
|
||||||
return -version_compare($a, $b);
|
|
||||||
});
|
|
||||||
$tags = array_filter($tags, function ($version)
|
|
||||||
{
|
|
||||||
return !preg_match("/[a-z]/i", $version);
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach ($tags as $tag => $version)
|
|
||||||
{
|
|
||||||
OsHelper::runValidated(
|
|
||||||
'git --no-pager diff --name-only --diff-filter D ' . escapeshellarg($tag),
|
|
||||||
$stdout
|
|
||||||
);
|
|
||||||
$removedFiles = explode("\n", trim($stdout));
|
|
||||||
foreach ($removedFiles as $removedFilePath)
|
|
||||||
{
|
|
||||||
OsHelper::runValidated(
|
|
||||||
'git --no-pager show ' . escapeshellarg($tag . ":" . $removedFilePath),
|
|
||||||
$stdout
|
|
||||||
);
|
|
||||||
$checksum = $this->checksum($stdout);
|
|
||||||
$item = self::array_get($checksums, $removedFilePath, []);
|
|
||||||
if (!in_array($checksum, $item)) $item["v{$version}"] = $checksum;
|
|
||||||
self::array_set($checksums, $removedFilePath, $item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $checksums;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item from an array using "slash" notation.
|
* Get an item from an array using "slash" notation.
|
||||||
*
|
*
|
||||||
@@ -229,10 +111,8 @@ class CoreImage
|
|||||||
|
|
||||||
if (isset($array[$key])) return $array[$key];
|
if (isset($array[$key])) return $array[$key];
|
||||||
|
|
||||||
foreach (explode('/', $key) as $segment)
|
foreach (explode('/', $key) as $segment) {
|
||||||
{
|
if (!is_array($array) || !array_key_exists($segment, $array)) {
|
||||||
if (!is_array($array) || !array_key_exists($segment, $array))
|
|
||||||
{
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,4 +121,84 @@ class CoreImage
|
|||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an array item to a given value using "slash" notation.
|
||||||
|
*
|
||||||
|
* If no key is given to the method, the entire array will be replaced.
|
||||||
|
*
|
||||||
|
* Based on Illuminate\Support\Arr::set()
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
* @param string|null $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @return array
|
||||||
|
* @copyright Copyright (c) Taylor Otwell
|
||||||
|
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
||||||
|
*/
|
||||||
|
private static function array_set(&$array, $key, $value)
|
||||||
|
{
|
||||||
|
if (is_null($key)) {
|
||||||
|
return $array = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = explode('/', $key);
|
||||||
|
|
||||||
|
while (count($keys) > 1) {
|
||||||
|
$key = array_shift($keys);
|
||||||
|
|
||||||
|
// If the key doesn't exist at this depth, we will just create an empty array
|
||||||
|
// to hold the next value, allowing us to create the arrays to hold final
|
||||||
|
// values at the correct depth. Then we'll keep digging into the array.
|
||||||
|
if (!isset($array[$key]) || !is_array($array[$key])) {
|
||||||
|
$array[$key] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$array = &$array[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
$array[array_shift($keys)] = $value;
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateRemovedChecksums($carry = [])
|
||||||
|
{
|
||||||
|
$checksums = $carry;
|
||||||
|
|
||||||
|
$stdout = '';
|
||||||
|
OsHelper::runValidated('git tag --list ' . escapeshellarg("v*"), $stdout);
|
||||||
|
$tags = explode("\n", trim($stdout));
|
||||||
|
$versions = [];
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$versions[] = preg_replace("/^v/", "", $tag);
|
||||||
|
}
|
||||||
|
$tags = array_combine($tags, $versions);
|
||||||
|
unset($versions);
|
||||||
|
uasort($tags, function ($a, $b) {
|
||||||
|
return -version_compare($a, $b);
|
||||||
|
});
|
||||||
|
$tags = array_filter($tags, function ($version) {
|
||||||
|
return !preg_match("/[a-z]/i", $version);
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach ($tags as $tag => $version) {
|
||||||
|
OsHelper::runValidated(
|
||||||
|
'git --no-pager diff --name-only --diff-filter D ' . escapeshellarg($tag),
|
||||||
|
$stdout
|
||||||
|
);
|
||||||
|
$removedFiles = explode("\n", trim($stdout));
|
||||||
|
foreach ($removedFiles as $removedFilePath) {
|
||||||
|
OsHelper::runValidated(
|
||||||
|
'git --no-pager show ' . escapeshellarg($tag . ":" . $removedFilePath),
|
||||||
|
$stdout
|
||||||
|
);
|
||||||
|
$checksum = $this->checksum($stdout);
|
||||||
|
$item = self::array_get($checksums, $removedFilePath, []);
|
||||||
|
if (!in_array($checksum, $item)) $item["v{$version}"] = $checksum;
|
||||||
|
self::array_set($checksums, $removedFilePath, $item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $checksums;
|
||||||
|
}
|
||||||
}
|
}
|
13
.github/workflows/build-release/e107_make.php
vendored
13
.github/workflows/build-release/e107_make.php
vendored
@@ -337,8 +337,8 @@ class e107Build
|
|||||||
|
|
||||||
$this->status('Creating TAR.GZ archive');
|
$this->status('Creating TAR.GZ archive');
|
||||||
OsHelper::runValidated("(cat $tarfile | gzip -9 > $tarfile.gz)");
|
OsHelper::runValidated("(cat $tarfile | gzip -9 > $tarfile.gz)");
|
||||||
// $this->status('Creating TAR.XZ archive');
|
$this->status('Creating TAR.XZ archive');
|
||||||
// $this->runValidated(cat $tarfile | xz -9e > $tarfile.xz)");
|
OsHelper::runValidated("(cat $tarfile | xz -9 > $tarfile.xz)");
|
||||||
|
|
||||||
$this->status('Removing TAR archive');
|
$this->status('Removing TAR archive');
|
||||||
unlink($tarfile);
|
unlink($tarfile);
|
||||||
@@ -514,13 +514,10 @@ class e107Build
|
|||||||
//create new image file - writes directly to cvsroot
|
//create new image file - writes directly to cvsroot
|
||||||
$this->changeDir($this->config['baseDir']);
|
$this->changeDir($this->config['baseDir']);
|
||||||
|
|
||||||
$_current = $this->exportDir;
|
$imageFile = $this->tempDir . "core_image.php";
|
||||||
$_deprecated = "{$this->config['baseDir']}/deprecated/{$this->config['main']['name']}";
|
|
||||||
|
|
||||||
$_image = $this->tempDir . "core_image.php";
|
$this->status("Creating new core_image.php file ({$imageFile})", true);
|
||||||
|
new CoreImage($this->exportDir, $this->version, $imageFile);
|
||||||
$this->status("Creating new core_image.php file ({$_image})", true);
|
|
||||||
new CoreImage($_current, $_deprecated, $_image);
|
|
||||||
|
|
||||||
$dir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export";
|
$dir = "{$this->config['baseDir']}/target/{$this->config['main']['name']}/export";
|
||||||
$this->changeDir($dir);
|
$this->changeDir($dir);
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6",
|
"php": ">=5.6",
|
||||||
|
"ext-json": "*",
|
||||||
|
"ext-pdo": "*",
|
||||||
"hybridauth/hybridauth": "^3.1.1",
|
"hybridauth/hybridauth": "^3.1.1",
|
||||||
"phpmailer/phpmailer": "^6.1",
|
"phpmailer/phpmailer": "^6.1",
|
||||||
"tedivm/jshrink": "^1.3",
|
"tedivm/jshrink": "^1.3",
|
||||||
|
Reference in New Issue
Block a user