Merge pull request #19321 from colemanw/profileGetFieldsFix
[civicrm-core.git] / CRM / Utils / Check / Component / Source.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component {
18
19 public function getRemovedFiles() {
20 $files[] = '[civicrm.packages]/Auth/SASL';
21 $files[] = '[civicrm.packages]/Auth/SASL.php';
22 $files[] = '[civicrm.packages]/Net/SMTP.php';
23 $files[] = '[civicrm.packages]/Net/Socket.php';
24 $files[] = '[civicrm.packages]/_ORIGINAL_/Net/SMTP.php';
25 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/Readme.md';
26 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/license.txt';
27 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.css';
28 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.min.css';
29 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables_themeroller.css';
30 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.js';
31 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.min.js';
32 $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.js';
33 $files[] = '[civicrm.vendor]/pear/net_smtp/examples';
34 $files[] = '[civicrm.vendor]/pear/net_smtp/tests';
35 $files[] = '[civicrm.vendor]/pear/net_smtp/phpdoc.sh';
36 $files[] = '[civicrm.vendor]/phpoffice/phpword/samples';
37 $files[] = '[civicrm.root]/templates/CRM/common/version.tpl';
38 $files[] = '[civicrm.packages]/Log.php';
39 $files[] = '[civicrm.packages]/_ORIGINAL_/Log.php';
40 $files[] = '[civicrm.packages]/Log/composite.php';
41 $files[] = '[civicrm.packages]/Log/console.php';
42 $files[] = '[civicrm.packages]/Log/daemon.php';
43 $files[] = '[civicrm.packages]/Log/display.php';
44 $files[] = '[civicrm.packages]/Log/error_log.php';
45 $files[] = '[civicrm.packages]/Log/file.php';
46 $files[] = '[civicrm.packages]/Log/firebug.php';
47 $files[] = '[civicrm.packages]/Log/mail.php';
48 $files[] = '[civicrm.packages]/Log/mcal.php';
49 $files[] = '[civicrm.packages]/Log/mdb2.php';
50 $files[] = '[civicrm.packages]/Log/null.php';
51 $files[] = '[civicrm.packages]/Log/observer.php';
52 $files[] = '[civicrm.packages]/Log/sql.php';
53 $files[] = '[civicrm.packages]/Log/sqlite.php';
54 $files[] = '[civicrm.packages]/Log/syslog.php';
55 $files[] = '[civicrm.packages]/Log/win.php';
56
57 return $files;
58 }
59
60 /**
61 * @return CRM_Utils_Check_Message[]
62 * Each item is an array with keys:
63 * - name: string, an abstract name
64 * - path: string, a full file path
65 * Files are returned in deletable order (ie children before parents).
66 */
67 public function findOrphanedFiles() {
68 $orphans = [];
69
70 foreach ($this->getRemovedFiles() as $file) {
71 $path = Civi::paths()->getPath($file);
72 if (empty($path) || strpos('[civicrm', $path) !== FALSE) {
73 Civi::log()->warning('Failed to resolve path of old file \"{file}\" ({path})', [
74 'file' => $file,
75 'path' => $path,
76 ]);
77 }
78 if (file_exists($path)) {
79 $orphans[] = [
80 'name' => $file,
81 'path' => $path,
82 ];
83 }
84 }
85
86 usort($orphans, function ($a, $b) {
87 // Children first, then parents.
88 $diff = strlen($b['name']) - strlen($a['name']);
89 if ($diff !== 0) {
90 return $diff;
91 }
92 if ($a['name'] === $b['name']) {
93 return 0;
94 }
95 return $a['name'] < $b['name'] ? -1 : 1;
96 });
97
98 return $orphans;
99 }
100
101 /**
102 * @return CRM_Utils_Check_Message[]
103 */
104 public function checkOrphans() {
105 $orphans = $this->findOrphanedFiles();
106 if (empty($orphans)) {
107 return [];
108 }
109
110 $messages = [];
111 $messages[] = new CRM_Utils_Check_Message(
112 __FUNCTION__,
113 ts('The local system includes old files which should not exist: "%1"',
114 [
115 1 => implode('", "', CRM_Utils_Array::collect('path', $orphans)),
116 ]),
117 ts('Old files'),
118 \Psr\Log\LogLevel::WARNING,
119 'fa-server'
120 );
121
122 return $messages;
123 }
124
125 }