Update copyright date for 2020
[civicrm-core.git] / CRM / Utils / Check / Component / Source.php
CommitLineData
dbc6b62a
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
dbc6b62a 5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
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
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
dbc6b62a
TO
32 */
33class 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';
4f897b75
SL
54 $files[] = '[civicrm.packages]/Log.php';
55 $files[] = '[civicrm.packages]/_ORIGINAL_/Log.php';
56 $files[] = '[civicrm.packages]/Log/composite.php';
57 $files[] = '[civicrm.packages]/Log/console.php';
58 $files[] = '[civicrm.packages]/Log/daemon.php';
59 $files[] = '[civicrm.packages]/Log/display.php';
60 $files[] = '[civicrm.packages]/Log/error_log.php';
61 $files[] = '[civicrm.packages]/Log/file.php';
62 $files[] = '[civicrm.packages]/Log/firebug.php';
63 $files[] = '[civicrm.packages]/Log/mail.php';
64 $files[] = '[civicrm.packages]/Log/mcal.php';
65 $files[] = '[civicrm.packages]/Log/mdb2.php';
66 $files[] = '[civicrm.packages]/Log/null.php';
67 $files[] = '[civicrm.packages]/Log/observer.php';
68 $files[] = '[civicrm.packages]/Log/sql.php';
69 $files[] = '[civicrm.packages]/Log/sqlite.php';
70 $files[] = '[civicrm.packages]/Log/syslog.php';
71 $files[] = '[civicrm.packages]/Log/win.php';
dbc6b62a
TO
72
73 return $files;
74 }
75
76 /**
77 * @return array
78 * Each item is an array with keys:
79 * - name: string, an abstract name
80 * - path: string, a full file path
81 * Files are returned in deletable order (ie children before parents).
82 */
83 public function findOrphanedFiles() {
be2fb01f 84 $orphans = [];
dbc6b62a
TO
85
86 foreach ($this->getRemovedFiles() as $file) {
87 $path = Civi::paths()->getPath($file);
88 if (empty($path) || strpos('[civicrm', $path) !== FALSE) {
be2fb01f 89 Civi::log()->warning('Failed to resolve path of old file \"{file}\" ({path})', [
dbc6b62a
TO
90 'file' => $file,
91 'path' => $path,
be2fb01f 92 ]);
dbc6b62a
TO
93 }
94 if (file_exists($path)) {
be2fb01f 95 $orphans[] = [
dbc6b62a
TO
96 'name' => $file,
97 'path' => $path,
be2fb01f 98 ];
dbc6b62a
TO
99 }
100 }
101
102 usort($orphans, function ($a, $b) {
103 // Children first, then parents.
104 $diff = strlen($b['name']) - strlen($a['name']);
105 if ($diff !== 0) {
106 return $diff;
107 }
108 if ($a['name'] === $b['name']) {
109 return 0;
110 }
111 return $a['name'] < $b['name'] ? -1 : 1;
112 });
113
114 return $orphans;
115 }
116
117 /**
118 * @return array
119 */
120 public function checkOrphans() {
121 $orphans = $this->findOrphanedFiles();
122 if (empty($orphans)) {
be2fb01f 123 return [];
dbc6b62a
TO
124 }
125
be2fb01f 126 $messages = [];
dbc6b62a
TO
127 $messages[] = new CRM_Utils_Check_Message(
128 __FUNCTION__,
129 ts('The local system includes old files which should not exist: "%1"',
be2fb01f 130 [
dbc6b62a 131 1 => implode('", "', CRM_Utils_Array::collect('path', $orphans)),
be2fb01f 132 ]),
dbc6b62a
TO
133 ts('Old files'),
134 \Psr\Log\LogLevel::WARNING,
135 'fa-server'
136 );
137
138 return $messages;
139 }
140
141}