From dbc6b62a0a6d952a90004b713c4f68a17b9be02f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 26 Jun 2017 23:35:36 -0700 Subject: [PATCH] CRM-20243 - Add check for deleted files --- CRM/Utils/Check/Component/Source.php | 129 +++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 CRM/Utils/Check/Component/Source.php diff --git a/CRM/Utils/Check/Component/Source.php b/CRM/Utils/Check/Component/Source.php new file mode 100644 index 0000000000..5a30b4adad --- /dev/null +++ b/CRM/Utils/Check/Component/Source.php @@ -0,0 +1,129 @@ +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})', array( + 'file' => $file, + 'path' => $path, + )); + } + if (file_exists($path)) { + $orphans[] = array( + 'name' => $file, + 'path' => $path, + ); + } + } + + 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; + } + + /** + * @return array + */ + public function checkOrphans() { + $orphans = $this->findOrphanedFiles(); + if (empty($orphans)) { + return array(); + } + + $messages = array(); + $messages[] = new CRM_Utils_Check_Message( + __FUNCTION__, + ts('The local system includes old files which should not exist: "%1"', + array( + 1 => implode('", "', CRM_Utils_Array::collect('path', $orphans)), + )), + ts('Old files'), + \Psr\Log\LogLevel::WARNING, + 'fa-server' + ); + + return $messages; + } + +} -- 2.25.1