From 90cafae0e99a36c72e3a42ab13492dd26b98678a Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 15 Dec 2023 10:09:07 -0500 Subject: [PATCH] dev/core#2607 - Switch checkOrphans to use generated list --- CRM/Utils/Check/Component/Source.php | 76 ++----------------- deleted-files-list.json | 4 + tools/scripts/generate-deleted-files-list.php | 7 ++ 3 files changed, 17 insertions(+), 70 deletions(-) diff --git a/CRM/Utils/Check/Component/Source.php b/CRM/Utils/Check/Component/Source.php index db16046422..4af45ff206 100644 --- a/CRM/Utils/Check/Component/Source.php +++ b/CRM/Utils/Check/Component/Source.php @@ -17,46 +17,8 @@ class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component { public function getRemovedFiles() { - $files[] = '[civicrm.packages]/Auth/SASL'; - $files[] = '[civicrm.packages]/Auth/SASL.php'; - $files[] = '[civicrm.packages]/Net/SMTP.php'; - $files[] = '[civicrm.packages]/Net/Socket.php'; - $files[] = '[civicrm.packages]/_ORIGINAL_/Net/SMTP.php'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/Readme.md'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/license.txt'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.css'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.min.css'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables_themeroller.css'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.js'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.min.js'; - $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.js'; - $files[] = '[civicrm.vendor]/pear/net_smtp/examples'; - $files[] = '[civicrm.vendor]/pear/net_smtp/tests'; - $files[] = '[civicrm.vendor]/pear/net_smtp/phpdoc.sh'; - $files[] = '[civicrm.vendor]/phpoffice/phpword/samples'; - $files[] = '[civicrm.root]/templates/CRM/common/version.tpl'; - // TODO: We need more proactive deletion for files like: - // $files[] = '[civicrm.root]/CRM/Contact/Import/Parser.php'; - $files[] = '[civicrm.packages]/Log.php'; - $files[] = '[civicrm.packages]/_ORIGINAL_/Log.php'; - $files[] = '[civicrm.packages]/Log/composite.php'; - $files[] = '[civicrm.packages]/Log/console.php'; - $files[] = '[civicrm.packages]/Log/daemon.php'; - $files[] = '[civicrm.packages]/Log/display.php'; - $files[] = '[civicrm.packages]/Log/error_log.php'; - $files[] = '[civicrm.packages]/Log/file.php'; - $files[] = '[civicrm.packages]/Log/firebug.php'; - $files[] = '[civicrm.packages]/Log/mail.php'; - $files[] = '[civicrm.packages]/Log/mcal.php'; - $files[] = '[civicrm.packages]/Log/mdb2.php'; - $files[] = '[civicrm.packages]/Log/null.php'; - $files[] = '[civicrm.packages]/Log/observer.php'; - $files[] = '[civicrm.packages]/Log/sql.php'; - $files[] = '[civicrm.packages]/Log/sqlite.php'; - $files[] = '[civicrm.packages]/Log/syslog.php'; - $files[] = '[civicrm.packages]/Log/win.php'; - - return $files; + $dataSource = Civi::paths()->getPath('[civicrm.root]/deleted-files-list.json'); + return json_decode(file_get_contents($dataSource), TRUE); } /** @@ -64,24 +26,12 @@ class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component { * Each item is an array with keys: * - name: string, an abstract name * - path: string, a full file path - * Files are returned in deletable order (ie children before parents). */ public function findOrphanedFiles() { $orphans = []; - $core_supplied_vendor = Civi::paths()->getPath('[civicrm.root]/vendor'); foreach ($this->getRemovedFiles() as $file) { - $path = Civi::paths()->getPath($file); - if (empty($path) || strpos('[civicrm', $path) !== FALSE) { - Civi::log()->warning('Failed to resolve path of old file \"{file}\" ({path})', [ - 'file' => $file, - 'path' => $path, - ]); - } - // If Vendor directory is not within the civicrm module directory (Drupal 8/9/10) etc ignore checks on the vendor paths. - if (strpos($file, '.vendor') !== FALSE && !is_dir($core_supplied_vendor)) { - continue; - } - if (file_exists($path)) { + $path = Civi::paths()->getPath("[civicrm.root]/$file"); + if (file_exists(rtrim($path, '/*'))) { $orphans[] = [ 'name' => $file, 'path' => $path, @@ -89,18 +39,6 @@ class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component { } } - usort($orphans, function ($a, $b) { - // Children first, then parents. - $diff = strlen($b['name']) - strlen($a['name']); - if ($diff !== 0) { - return $diff; - } - if ($a['name'] === $b['name']) { - return 0; - } - return $a['name'] < $b['name'] ? -1 : 1; - }); - return $orphans; } @@ -116,10 +54,8 @@ class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component { $messages = []; $messages[] = new CRM_Utils_Check_Message( __FUNCTION__, - ts('The local system includes old files which should not exist: "%1"', - [ - 1 => implode('", "', CRM_Utils_Array::collect('path', $orphans)), - ]), + ts('The local system includes old files which should not exist:') . + '', ts('Old files'), \Psr\Log\LogLevel::WARNING, 'fa-server' diff --git a/deleted-files-list.json b/deleted-files-list.json index eefc6b023b..e22bd3a5f6 100644 --- a/deleted-files-list.json +++ b/deleted-files-list.json @@ -1024,6 +1024,10 @@ "tools/templates/*", "tools/tests/*", "tools/xml/*", + "vendor/pear/net_smtp/examples/*", + "vendor/pear/net_smtp/phpdoc.sh", + "vendor/pear/net_smtp/tests/*", + "vendor/phpoffice/phpword/samples/*", "xml/schema/Activity/ActivityAssignment.xml", "xml/schema/Activity/ActivityTarget.xml", "xml/schema/Bridge/*", diff --git a/tools/scripts/generate-deleted-files-list.php b/tools/scripts/generate-deleted-files-list.php index bf71cdeb22..5210a7a5af 100755 --- a/tools/scripts/generate-deleted-files-list.php +++ b/tools/scripts/generate-deleted-files-list.php @@ -45,6 +45,13 @@ $prefix = 'packages/'; $logString = `(cd $prefix && git log $minVer...HEAD --diff-filter=D --summary | grep delete)`; parseLog($logString, $deletedFiles, $prefix); +// Vendor: these files are managed by composer not git. +// for lack of anything more clever here's a hand-curated list. +$deletedFiles[] = 'vendor/pear/net_smtp/examples/*'; +$deletedFiles[] = 'vendor/pear/net_smtp/tests/*'; +$deletedFiles[] = 'vendor/pear/net_smtp/phpdoc.sh'; +$deletedFiles[] = 'vendor/phpoffice/phpword/samples/*'; + $deletedFiles = array_unique($deletedFiles); sort($deletedFiles); $fileName = 'deleted-files-list.json'; -- 2.25.1