Commit | Line | Data |
---|---|---|
dbc6b62a TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
dbc6b62a TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
dbc6b62a TO |
32 | */ |
33 | class CRM_Utils_Check_Component_Source extends CRM_Utils_Check_Component { | |
34 | ||
35 | public function getRemovedFiles() { | |
36 | $files[] = '[civicrm.packages]/Auth/SASL'; | |
37 | $files[] = '[civicrm.packages]/Auth/SASL.php'; | |
dbc6b62a TO |
38 | $files[] = '[civicrm.packages]/Net/SMTP.php'; |
39 | $files[] = '[civicrm.packages]/Net/Socket.php'; | |
40 | $files[] = '[civicrm.packages]/_ORIGINAL_/Net/SMTP.php'; | |
41 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/Readme.md'; | |
42 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/license.txt'; | |
43 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.css'; | |
44 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables.min.css'; | |
45 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/css/jquery.dataTables_themeroller.css'; | |
46 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.js'; | |
47 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.dataTables.min.js'; | |
48 | $files[] = '[civicrm.packages]/jquery/plugins/DataTables/media/js/jquery.js'; | |
49 | $files[] = '[civicrm.vendor]/pear/net_smtp/examples'; | |
50 | $files[] = '[civicrm.vendor]/pear/net_smtp/tests'; | |
51 | $files[] = '[civicrm.vendor]/pear/net_smtp/phpdoc.sh'; | |
52 | $files[] = '[civicrm.vendor]/phpoffice/phpword/samples'; | |
6c9d7e1f | 53 | $files[] = '[civicrm.root]/templates/CRM/common/version.tpl'; |
dbc6b62a TO |
54 | |
55 | return $files; | |
56 | } | |
57 | ||
58 | /** | |
59 | * @return array | |
60 | * Each item is an array with keys: | |
61 | * - name: string, an abstract name | |
62 | * - path: string, a full file path | |
63 | * Files are returned in deletable order (ie children before parents). | |
64 | */ | |
65 | public function findOrphanedFiles() { | |
66 | $orphans = array(); | |
67 | ||
68 | foreach ($this->getRemovedFiles() as $file) { | |
69 | $path = Civi::paths()->getPath($file); | |
70 | if (empty($path) || strpos('[civicrm', $path) !== FALSE) { | |
71 | Civi::log()->warning('Failed to resolve path of old file \"{file}\" ({path})', array( | |
72 | 'file' => $file, | |
73 | 'path' => $path, | |
74 | )); | |
75 | } | |
76 | if (file_exists($path)) { | |
77 | $orphans[] = array( | |
78 | 'name' => $file, | |
79 | 'path' => $path, | |
80 | ); | |
81 | } | |
82 | } | |
83 | ||
84 | usort($orphans, function ($a, $b) { | |
85 | // Children first, then parents. | |
86 | $diff = strlen($b['name']) - strlen($a['name']); | |
87 | if ($diff !== 0) { | |
88 | return $diff; | |
89 | } | |
90 | if ($a['name'] === $b['name']) { | |
91 | return 0; | |
92 | } | |
93 | return $a['name'] < $b['name'] ? -1 : 1; | |
94 | }); | |
95 | ||
96 | return $orphans; | |
97 | } | |
98 | ||
99 | /** | |
100 | * @return array | |
101 | */ | |
102 | public function checkOrphans() { | |
103 | $orphans = $this->findOrphanedFiles(); | |
104 | if (empty($orphans)) { | |
105 | return array(); | |
106 | } | |
107 | ||
108 | $messages = array(); | |
109 | $messages[] = new CRM_Utils_Check_Message( | |
110 | __FUNCTION__, | |
111 | ts('The local system includes old files which should not exist: "%1"', | |
112 | array( | |
113 | 1 => implode('", "', CRM_Utils_Array::collect('path', $orphans)), | |
114 | )), | |
115 | ts('Old files'), | |
116 | \Psr\Log\LogLevel::WARNING, | |
117 | 'fa-server' | |
118 | ); | |
119 | ||
120 | return $messages; | |
121 | } | |
122 | ||
123 | } |