From 8fa7890f18eced8db55d8cfa612338c652dff0ba Mon Sep 17 00:00:00 2001 From: mystralkk Date: Thu, 14 May 2020 13:38:23 +0900 Subject: [PATCH 1/3] Added ability to Create A Geeklog Upgrade Package from Phing (feature #1009) --- build.properties | 16 +- build.xml | 92 +++++++---- system/build/tasks/MyDiffTask.php | 49 +++--- .../tasks/MyRemoveUnchangedFilesTask.php | 154 ++++++++++++++++++ system/build/tasks/MyTaskCommon.php | 27 +++ 5 files changed, 274 insertions(+), 64 deletions(-) create mode 100644 system/build/tasks/MyRemoveUnchangedFilesTask.php create mode 100644 system/build/tasks/MyTaskCommon.php diff --git a/build.properties b/build.properties index 881940718..5b5fc0041 100644 --- a/build.properties +++ b/build.properties @@ -1,8 +1,11 @@ # Property files contain key=value pairs -# Geeklog version number +## Geeklog version number ## version=2.2.2 +## Geeklog previous version number +previousVersion=2.2.1sr1 + # Git hash tag for the previous version of Geeklog. e.g., "936264c" for Geeklog 2.1.3 previousVersionSHA=79296e7 # previousVersionSHA - Geeklog 2.2.1sr1 (79296e7) @@ -11,3 +14,14 @@ previousVersionSHA=79296e7 # Git hash tag for the current version of Geeklog. May be left empty. currentVersionSHA= + +## Directory / File permissions ## + +# dir with write permission +perm_dir_w=0777 + +# file with execute permission +perm_file_x=0755 + +# file with write permission +perm_file_w=0666 diff --git a/build.xml b/build.xml index 3eb60baf9..f40479e6a 100644 --- a/build.xml +++ b/build.xml @@ -7,7 +7,8 @@ - + + @@ -22,9 +23,12 @@ - + + + + @@ -64,9 +68,9 @@ - - - + + + @@ -110,60 +114,60 @@ - - - - - - - - + + + + + + + + - - + + - - + + - - - - - - - - + + + + + + + + - - + + - - - - - + + + + + - + @@ -176,4 +180,26 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/system/build/tasks/MyDiffTask.php b/system/build/tasks/MyDiffTask.php index 95fdd6b47..6cb2aeefd 100644 --- a/system/build/tasks/MyDiffTask.php +++ b/system/build/tasks/MyDiffTask.php @@ -1,6 +1,6 @@ startsWith = MyTaskCommon::$startsWith; + $this->excludes = MyTaskCommon::$excludes; + return true; } /** * Setter for the attribute "previousVersionSHA" * - * @param string $version + * @param string $version */ public function setPreviousVersionSHA($version) { @@ -58,7 +49,7 @@ public function setPreviousVersionSHA($version) /** * Setter for the attribute "currentVersionSHA" * - * @param string $version + * @param string $version */ public function setCurrentVersionSHA($version) { @@ -68,7 +59,7 @@ public function setCurrentVersionSHA($version) /** * Return if a given path should be included in diff result * - * @param string $path + * @param string $path * @return bool true if the $path should be included in diff result */ private function shouldInclude($path) @@ -79,7 +70,7 @@ private function shouldInclude($path) } } - foreach ($this->includes as $needle2) { + foreach ($this->excludes as $needle2) { if (strpos($path, $needle2) > 0) { return false; } @@ -95,20 +86,18 @@ public function main() { $currentDir = getcwd(); chdir(__DIR__ . '/../../../'); + exec('git config diff.renameLimit 999999'); - exec('git config diff.renameLimit 999999'); - - // Create 'changed-files' - exec(sprintf('git diff --name-only %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); + // Create the 'changed-files' file + exec(sprintf('git diff --name-only --diff-filter=ACMR %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); $changedFiles = array_filter($lines, [$this, 'shouldInclude']); @file_put_contents('./public_html/docs/changed-files', implode("\n", $changedFiles) . "\n"); - // Create 'removed-files' + // Create the 'removed-files' file unset($lines); - exec(sprintf('git diff --name-only --diff-filter=ACMRTUX %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); - $otherFiles = array_filter($lines, [$this, 'shouldInclude']); - $otherFiles = array_diff($changedFiles, $otherFiles); - @file_put_contents('./public_html/docs/removed-files', implode("\n", $otherFiles) . "\n"); + exec(sprintf('git diff --name-only --diff-filter=R %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); + $removedFiles = array_filter($lines, [$this, 'shouldInclude']); + @file_put_contents('./public_html/docs/removed-files', implode("\n", $removedFiles) . "\n"); exec('git config --unset diff.renameLimit'); diff --git a/system/build/tasks/MyRemoveUnchangedFilesTask.php b/system/build/tasks/MyRemoveUnchangedFilesTask.php new file mode 100644 index 000000000..e33bc11f0 --- /dev/null +++ b/system/build/tasks/MyRemoveUnchangedFilesTask.php @@ -0,0 +1,154 @@ +startsWith = MyTaskCommon::$startsWith; + $this->excludes = MyTaskCommon::$excludes; + + return true; + } + + /** + * Setter for the attribute "previousVersionSHA" + * + * @param string $version + */ + public function setPreviousVersionSHA($version) + { + $this->previousVersionSHA = $version; + } + + /** + * Setter for the attribute "currentVersionSHA" + * + * @param string $version + */ + public function setCurrentVersionSHA($version) + { + $this->currentVersionSHA = $version; + } + + /** + * Setter for the attribute "dstDir" + * + * @param string $dir + */ + public function setDstDir($dir) + { + $this->dstDir = str_replace('/\\', '/', $dir) . '/'; + } + + /** + * Return if a given path should be included in diff result + * + * @param string $path + * @return bool true if the $path should be included in diff result + */ + private function shouldInclude($path) + { + foreach ($this->startsWith as $needle) { + if (strpos($path, $needle) === 0) { + return false; + } + } + + foreach ($this->excludes as $needle2) { + if (strpos($path, $needle2) > 0) { + return false; + } + } + + return true; + } + + /** + * Remove files to exclude from the upgrade package + * + * @param string $dir current directory + */ + private function removeUnnecessaryFiles($dir) + { + foreach (scandir($dir) as $item) { + if (($item === '.') || ($item === '..')) { + continue; + } + + $path = $dir . $item; + + if (is_dir($path)) { + $this->removeUnnecessaryFiles($path . '/'); + } else { + $relativePath = str_ireplace($this->dstDir, '', $path); + + if (!in_array($path, $this->filesToInclude) || !$this->shouldInclude($path)) { + @unlink($path); + } + } + } + } + + /** + * Create an upgrade distribution tarball + */ + public function main() + { + $currentDir = getcwd(); + chdir(__DIR__ . '/../../../'); + exec('git config diff.renameLimit 999999'); + + exec(sprintf('git diff --name-only --diff-filter=ACMR %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); + $this->filesToInclude = array_filter($lines, [$this, 'shouldInclude']); + $this->removeUnnecessaryFiles($this->dstDir); + + // Create the 'removed-files' file + unset($lines); + exec(sprintf('git diff --name-only --diff-filter=R %s %s', $this->previousVersionSHA, $this->currentVersionSHA), $lines); + $removedFiles = array_filter($lines, [$this, 'shouldInclude']); + @file_put_contents('./public_html/docs/removed-files', implode("\n", $removedFiles) . "\n"); + + exec('git config --unset diff.renameLimit'); + + if ($currentDir !== false) { + chdir($currentDir); + } + + } +} diff --git a/system/build/tasks/MyTaskCommon.php b/system/build/tasks/MyTaskCommon.php new file mode 100644 index 000000000..dbae11cfe --- /dev/null +++ b/system/build/tasks/MyTaskCommon.php @@ -0,0 +1,27 @@ + Date: Thu, 14 May 2020 13:51:33 +0900 Subject: [PATCH 2/3] Added "RECAPTCHA_SUPPORT_V3" constant --- system/build/lm/lm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/build/lm/lm.php b/system/build/lm/lm.php index 1163c8055..52f9424bf 100644 --- a/system/build/lm/lm.php +++ b/system/build/lm/lm.php @@ -81,6 +81,7 @@ define('RECAPTCHA_NO_SUPPORT', 0); define('RECAPTCHA_SUPPORT_V2', 1); define('RECAPTCHA_SUPPORT_V2_INVISIBLE', 2); +define('RECAPTCHA_SUPPORT_V3', 4); // list of all variables accessed in the language file $_DB_mysqldump_path = '{$_DB_mysqldump_path}'; From 4a7a64891cbb9c9da345eda7c76a4b160638c28b Mon Sep 17 00:00:00 2001 From: mystralkk Date: Thu, 14 May 2020 14:53:56 +0900 Subject: [PATCH 3/3] Fixed the wrong paths --- build.properties | 18 +++++++++++++++--- build.xml | 2 +- .../build/tasks/MyRemoveUnchangedFilesTask.php | 7 ++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/build.properties b/build.properties index 5b5fc0041..b79192da7 100644 --- a/build.properties +++ b/build.properties @@ -1,13 +1,25 @@ # Property files contain key=value pairs -## Geeklog version number ## +################################################################################# +# +# You should set: +# 1. version +# 2. previousVersion +# 3. previousVersionSHA +# +# before building +# +################################################################################## +# +## 1. Geeklog version number ## version=2.2.2 -## Geeklog previous version number +## 2. Geeklog previous version number previousVersion=2.2.1sr1 -# Git hash tag for the previous version of Geeklog. e.g., "936264c" for Geeklog 2.1.3 +# 3. Git hash tag for the previous version of Geeklog. e.g., "936264c" for Geeklog 2.1.3 previousVersionSHA=79296e7 + # previousVersionSHA - Geeklog 2.2.1sr1 (79296e7) # previousVersionSHA - Geeklog 2.2.1 (860e7e6) # previousVersionSHA - Geeklog 2.2.0 (c7c2760) diff --git a/build.xml b/build.xml index f40479e6a..4607ca0c6 100644 --- a/build.xml +++ b/build.xml @@ -68,7 +68,7 @@ - + diff --git a/system/build/tasks/MyRemoveUnchangedFilesTask.php b/system/build/tasks/MyRemoveUnchangedFilesTask.php index e33bc11f0..5c8903705 100644 --- a/system/build/tasks/MyRemoveUnchangedFilesTask.php +++ b/system/build/tasks/MyRemoveUnchangedFilesTask.php @@ -118,11 +118,16 @@ private function removeUnnecessaryFiles($dir) } else { $relativePath = str_ireplace($this->dstDir, '', $path); - if (!in_array($path, $this->filesToInclude) || !$this->shouldInclude($path)) { + if (!in_array($relativePath, $this->filesToInclude) || !$this->shouldInclude($relativePath)) { @unlink($path); } } } + + // Remove an empty directory + if (count(scandir($dir)) === 2) { + @rmdir($dir); + } } /**