xref: /webtrees/app/Services/HousekeepingService.php (revision 4459dc9a6d0c27769f8135175f3569e4fa287451)
1a3dc3edaSGreg Roach<?php
2a3dc3edaSGreg Roach/**
3a3dc3edaSGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5a3dc3edaSGreg Roach * This program is free software: you can redistribute it and/or modify
6a3dc3edaSGreg Roach * it under the terms of the GNU General Public License as published by
7a3dc3edaSGreg Roach * the Free Software Foundation, either version 3 of the License, or
8a3dc3edaSGreg Roach * (at your option) any later version.
9a3dc3edaSGreg Roach * This program is distributed in the hope that it will be useful,
10a3dc3edaSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a3dc3edaSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12a3dc3edaSGreg Roach * GNU General Public License for more details.
13a3dc3edaSGreg Roach * You should have received a copy of the GNU General Public License
14a3dc3edaSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15a3dc3edaSGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
18a3dc3edaSGreg Roachnamespace Fisharebest\Webtrees\Services;
19a3dc3edaSGreg Roach
20a3dc3edaSGreg Roachuse Exception;
21*4459dc9aSGreg Roachuse Fisharebest\Webtrees\Carbon;
22e5c19fcdSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
23a3dc3edaSGreg Roachuse League\Flysystem\Filesystem;
24a3dc3edaSGreg Roach
25a3dc3edaSGreg Roach/**
26a3dc3edaSGreg Roach * Clean up old data, files and folders.
27a3dc3edaSGreg Roach */
28a3dc3edaSGreg Roachclass HousekeepingService
29a3dc3edaSGreg Roach{
30a3dc3edaSGreg Roach    // This is a list of old files and directories, from earlier versions of webtrees.
31a3dc3edaSGreg Roach    // git diff 1.7.9..master --name-status | grep ^D
3216d6367aSGreg Roach    private const OLD_PATHS = [
33a3dc3edaSGreg Roach        // Removed in 1.0.2
34a3dc3edaSGreg Roach        'language/en.mo',
35a3dc3edaSGreg Roach        // Removed in 1.0.3
36a3dc3edaSGreg Roach        'themechange.php',
37a3dc3edaSGreg Roach        // Removed in 1.1.0
38a3dc3edaSGreg Roach        'addremotelink.php',
39a3dc3edaSGreg Roach        'addsearchlink.php',
40a3dc3edaSGreg Roach        'client.php',
41a3dc3edaSGreg Roach        'dir_editor.php',
42a3dc3edaSGreg Roach        'editconfig_gedcom.php',
43a3dc3edaSGreg Roach        'editgedcoms.php',
44a3dc3edaSGreg Roach        'edit_merge.php',
45a3dc3edaSGreg Roach        'edit_news.php',
46a3dc3edaSGreg Roach        'genservice.php',
47a3dc3edaSGreg Roach        'logs.php',
48a3dc3edaSGreg Roach        'manageservers.php',
49a3dc3edaSGreg Roach        'media.php',
50a3dc3edaSGreg Roach        'module_admin.php',
51a3dc3edaSGreg Roach        //WT_ROOT.'modules', // Do not delete - users may have stored custom modules/data here
52a3dc3edaSGreg Roach        'opensearch.php',
53a3dc3edaSGreg Roach        'PEAR.php',
54a3dc3edaSGreg Roach        'pgv_to_wt.php',
55a3dc3edaSGreg Roach        'places',
56a3dc3edaSGreg Roach        //WT_ROOT.'robots.txt', // Do not delete this - it may contain user data
57a3dc3edaSGreg Roach        'serviceClientTest.php',
58a3dc3edaSGreg Roach        'siteconfig.php',
59a3dc3edaSGreg Roach        'SOAP',
60a3dc3edaSGreg Roach        'themes/clouds/mozilla.css',
61a3dc3edaSGreg Roach        'themes/clouds/netscape.css',
62a3dc3edaSGreg Roach        'themes/colors/mozilla.css',
63a3dc3edaSGreg Roach        'themes/colors/netscape.css',
64a3dc3edaSGreg Roach        'themes/fab/mozilla.css',
65a3dc3edaSGreg Roach        'themes/fab/netscape.css',
66a3dc3edaSGreg Roach        'themes/minimal/mozilla.css',
67a3dc3edaSGreg Roach        'themes/minimal/netscape.css',
68a3dc3edaSGreg Roach        'themes/webtrees/mozilla.css',
69a3dc3edaSGreg Roach        'themes/webtrees/netscape.css',
70a3dc3edaSGreg Roach        'themes/webtrees/style_rtl.css',
71a3dc3edaSGreg Roach        'themes/xenea/mozilla.css',
72a3dc3edaSGreg Roach        'themes/xenea/netscape.css',
73a3dc3edaSGreg Roach        'uploadmedia.php',
74a3dc3edaSGreg Roach        'useradmin.php',
75a3dc3edaSGreg Roach        'webservice',
76a3dc3edaSGreg Roach        'wtinfo.php',
77a3dc3edaSGreg Roach        // Removed in 1.1.2
78a3dc3edaSGreg Roach        'treenav.php',
79a3dc3edaSGreg Roach        // Removed in 1.2.0
80a3dc3edaSGreg Roach        'themes/clouds/jquery',
81a3dc3edaSGreg Roach        'themes/colors/jquery',
82a3dc3edaSGreg Roach        'themes/fab/jquery',
83a3dc3edaSGreg Roach        'themes/minimal/jquery',
84a3dc3edaSGreg Roach        'themes/webtrees/jquery',
85a3dc3edaSGreg Roach        'themes/xenea/jquery',
86a3dc3edaSGreg Roach        // Removed in 1.2.2
87a3dc3edaSGreg Roach        'themes/clouds/chrome.css',
88a3dc3edaSGreg Roach        'themes/clouds/opera.css',
89a3dc3edaSGreg Roach        'themes/clouds/print.css',
90a3dc3edaSGreg Roach        'themes/clouds/style_rtl.css',
91a3dc3edaSGreg Roach        'themes/colors/chrome.css',
92a3dc3edaSGreg Roach        'themes/colors/opera.css',
93a3dc3edaSGreg Roach        'themes/colors/print.css',
94a3dc3edaSGreg Roach        'themes/colors/style_rtl.css',
95a3dc3edaSGreg Roach        'themes/fab/chrome.css',
96a3dc3edaSGreg Roach        'themes/fab/opera.css',
97a3dc3edaSGreg Roach        'themes/minimal/chrome.css',
98a3dc3edaSGreg Roach        'themes/minimal/opera.css',
99a3dc3edaSGreg Roach        'themes/minimal/print.css',
100a3dc3edaSGreg Roach        'themes/minimal/style_rtl.css',
101a3dc3edaSGreg Roach        'themes/xenea/chrome.css',
102a3dc3edaSGreg Roach        'themes/xenea/opera.css',
103a3dc3edaSGreg Roach        'themes/xenea/print.css',
104a3dc3edaSGreg Roach        'themes/xenea/style_rtl.css',
105a3dc3edaSGreg Roach        // Removed in 1.2.3
10649a243cbSGreg Roach        'modules_v2',
107a3dc3edaSGreg Roach        // Removed in 1.2.4
108a3dc3edaSGreg Roach        'search_engine.php',
109a3dc3edaSGreg Roach        'themes/clouds/modules.css',
110a3dc3edaSGreg Roach        'themes/colors/modules.css',
111a3dc3edaSGreg Roach        'themes/fab/modules.css',
112a3dc3edaSGreg Roach        'themes/minimal/modules.css',
113a3dc3edaSGreg Roach        'themes/webtrees/modules.css',
114a3dc3edaSGreg Roach        'themes/xenea/modules.css',
115a3dc3edaSGreg Roach        // Removed in 1.2.5
116a3dc3edaSGreg Roach        'sidebar.php',
117a3dc3edaSGreg Roach        // Removed in 1.2.6
118a3dc3edaSGreg Roach        // Removed in 1.2.7
119a3dc3edaSGreg Roach        'login_register.php',
120a3dc3edaSGreg Roach        // Removed in 1.3.0
121a3dc3edaSGreg Roach        'admin_site_ipaddress.php',
122a3dc3edaSGreg Roach        'downloadgedcom.php',
123a3dc3edaSGreg Roach        'export_gedcom.php',
124a3dc3edaSGreg Roach        'gedcheck.php',
125a3dc3edaSGreg Roach        'images',
126a3dc3edaSGreg Roach        // Removed in 1.3.1
127a3dc3edaSGreg Roach        'imageflush.php',
12849a243cbSGreg Roach        '/lightbox/js/tip_balloon_RTL.js',
129a3dc3edaSGreg Roach        // Removed in 1.4.0
130a3dc3edaSGreg Roach        'imageview.php',
131a3dc3edaSGreg Roach        'media/MediaInfo.txt',
132a3dc3edaSGreg Roach        'media/thumbs/ThumbsInfo.txt',
133a3dc3edaSGreg Roach        'themes/webtrees/chrome.css',
134a3dc3edaSGreg Roach        // Removed in 1.4.2
135a3dc3edaSGreg Roach        'themes/clouds/jquery-ui-1.10.0',
136a3dc3edaSGreg Roach        'themes/colors/jquery-ui-1.10.0',
137a3dc3edaSGreg Roach        'themes/fab/jquery-ui-1.10.0',
138a3dc3edaSGreg Roach        'themes/minimal/jquery-ui-1.10.0',
139a3dc3edaSGreg Roach        'themes/webtrees/jquery-ui-1.10.0',
140a3dc3edaSGreg Roach        'themes/xenea/jquery-ui-1.10.0',
141a3dc3edaSGreg Roach        // Removed in 1.5.0
142a3dc3edaSGreg Roach        'themes/clouds/favicon.png',
143a3dc3edaSGreg Roach        'themes/clouds/images',
144a3dc3edaSGreg Roach        'themes/clouds/msie.css',
145a3dc3edaSGreg Roach        'themes/clouds/style.css',
146a3dc3edaSGreg Roach        'themes/colors/css',
147a3dc3edaSGreg Roach        'themes/colors/favicon.png',
148a3dc3edaSGreg Roach        'themes/colors/images',
149a3dc3edaSGreg Roach        'themes/colors/ipad.css',
150a3dc3edaSGreg Roach        'themes/colors/msie.css',
151a3dc3edaSGreg Roach        'themes/fab/favicon.png',
152a3dc3edaSGreg Roach        'themes/fab/images',
153a3dc3edaSGreg Roach        'themes/fab/msie.css',
154a3dc3edaSGreg Roach        'themes/fab/style.css',
155a3dc3edaSGreg Roach        'themes/minimal/favicon.png',
156a3dc3edaSGreg Roach        'themes/minimal/images',
157a3dc3edaSGreg Roach        'themes/minimal/msie.css',
158a3dc3edaSGreg Roach        'themes/minimal/style.css',
159a3dc3edaSGreg Roach        'themes/webtrees/favicon.png',
160a3dc3edaSGreg Roach        'themes/webtrees/images',
161a3dc3edaSGreg Roach        'themes/webtrees/msie.css',
162a3dc3edaSGreg Roach        'themes/webtrees/style.css',
163a3dc3edaSGreg Roach        'themes/xenea/favicon.png',
164a3dc3edaSGreg Roach        'themes/xenea/images',
165a3dc3edaSGreg Roach        'themes/xenea/msie.css',
166a3dc3edaSGreg Roach        'themes/xenea/style.css',
167a3dc3edaSGreg Roach        // Removed in 1.5.1
168a3dc3edaSGreg Roach        'themes/clouds/css-1.5.0',
169a3dc3edaSGreg Roach        'themes/colors/css-1.5.0',
170a3dc3edaSGreg Roach        'themes/fab/css-1.5.0',
171a3dc3edaSGreg Roach        'themes/minimal/css-1.5.0',
172a3dc3edaSGreg Roach        'themes/webtrees/css-1.5.0',
173a3dc3edaSGreg Roach        'themes/xenea/css-1.5.0',
174a3dc3edaSGreg Roach        // Removed in 1.5.2
175a3dc3edaSGreg Roach        'themes/clouds/css-1.5.1',
176a3dc3edaSGreg Roach        'themes/colors/css-1.5.1',
177a3dc3edaSGreg Roach        'themes/fab/css-1.5.1',
178a3dc3edaSGreg Roach        'themes/minimal/css-1.5.1',
179a3dc3edaSGreg Roach        'themes/webtrees/css-1.5.1',
180a3dc3edaSGreg Roach        'themes/xenea/css-1.5.1',
181a3dc3edaSGreg Roach        // Removed in 1.5.3
182a3dc3edaSGreg Roach        'readme.html',
183a3dc3edaSGreg Roach        'themes/clouds/css-1.5.2',
184a3dc3edaSGreg Roach        'themes/colors/css-1.5.2',
185a3dc3edaSGreg Roach        'themes/fab/css-1.5.2',
186a3dc3edaSGreg Roach        'themes/minimal/css-1.5.2',
187a3dc3edaSGreg Roach        'themes/webtrees/css-1.5.2',
188a3dc3edaSGreg Roach        'themes/xenea/css-1.5.2',
189a3dc3edaSGreg Roach        // Removed in 1.6.0
190a3dc3edaSGreg Roach        'downloadbackup.php',
191a3dc3edaSGreg Roach        'site-php-version.php',
192a3dc3edaSGreg Roach        'themes/clouds/css-1.5.3',
193a3dc3edaSGreg Roach        'themes/colors/css-1.5.3',
194a3dc3edaSGreg Roach        'themes/fab/css-1.5.3',
195a3dc3edaSGreg Roach        'themes/minimal/css-1.5.3',
196a3dc3edaSGreg Roach        'themes/webtrees/css-1.5.3',
197a3dc3edaSGreg Roach        'themes/xenea/css-1.5.3',
198a3dc3edaSGreg Roach        // Removed in 1.6.2
199a3dc3edaSGreg Roach        'themes/clouds/jquery-ui-1.10.3',
200a3dc3edaSGreg Roach        'themes/colors/css-1.6.0',
201a3dc3edaSGreg Roach        'themes/colors/jquery-ui-1.10.3',
202a3dc3edaSGreg Roach        'themes/fab/css-1.6.0',
203a3dc3edaSGreg Roach        'themes/fab/jquery-ui-1.10.3',
204a3dc3edaSGreg Roach        'themes/minimal/css-1.6.0',
205a3dc3edaSGreg Roach        'themes/minimal/jquery-ui-1.10.3',
206a3dc3edaSGreg Roach        'themes/webtrees/css-1.6.0',
207a3dc3edaSGreg Roach        'themes/webtrees/jquery-ui-1.10.3',
208a3dc3edaSGreg Roach        'themes/xenea/css-1.6.0',
209a3dc3edaSGreg Roach        'themes/xenea/jquery-ui-1.10.3',
210a3dc3edaSGreg Roach        // Removed in 1.7.0
211a3dc3edaSGreg Roach        'admin_site_other.php',
212a3dc3edaSGreg Roach        'js',
213a3dc3edaSGreg Roach        'language/en_GB.mo',
214a3dc3edaSGreg Roach        // Replaced with en-GB.mo
215a3dc3edaSGreg Roach        'language/en_US.mo',
216a3dc3edaSGreg Roach        // Replaced with en-US.mo
217a3dc3edaSGreg Roach        'language/pt_BR.mo',
218a3dc3edaSGreg Roach        // Replaced with pt-BR.mo
219a3dc3edaSGreg Roach        'language/zh_CN.mo',
220a3dc3edaSGreg Roach        // Replaced with zh-Hans.mo
221a3dc3edaSGreg Roach        'language/extra',
222a3dc3edaSGreg Roach        'library',
223a3dc3edaSGreg Roach        'save.php',
224a3dc3edaSGreg Roach        'themes/clouds/css-1.6.2',
225a3dc3edaSGreg Roach        'themes/clouds/templates',
226a3dc3edaSGreg Roach        'themes/clouds/header.php',
227a3dc3edaSGreg Roach        'themes/clouds/footer.php',
228a3dc3edaSGreg Roach        'themes/colors/css-1.6.2',
229a3dc3edaSGreg Roach        'themes/colors/templates',
230a3dc3edaSGreg Roach        'themes/colors/header.php',
231a3dc3edaSGreg Roach        'themes/colors/footer.php',
232a3dc3edaSGreg Roach        'themes/fab/css-1.6.2',
233a3dc3edaSGreg Roach        'themes/fab/templates',
234a3dc3edaSGreg Roach        'themes/fab/header.php',
235a3dc3edaSGreg Roach        'themes/fab/footer.php',
236a3dc3edaSGreg Roach        'themes/minimal/css-1.6.2',
237a3dc3edaSGreg Roach        'themes/minimal/templates',
238a3dc3edaSGreg Roach        'themes/minimal/header.php',
239a3dc3edaSGreg Roach        'themes/minimal/footer.php',
240a3dc3edaSGreg Roach        'themes/webtrees/css-1.6.2',
241a3dc3edaSGreg Roach        'themes/webtrees/templates',
242a3dc3edaSGreg Roach        'themes/webtrees/header.php',
243a3dc3edaSGreg Roach        'themes/webtrees/footer.php',
244a3dc3edaSGreg Roach        'themes/xenea/css-1.6.2',
245a3dc3edaSGreg Roach        'themes/xenea/templates',
246a3dc3edaSGreg Roach        'themes/xenea/header.php',
247a3dc3edaSGreg Roach        'themes/xenea/footer.php',
248a3dc3edaSGreg Roach        // Removed in 1.7.2
249a3dc3edaSGreg Roach        'assets/js-1.7.0',
250a3dc3edaSGreg Roach        // Removed in 1.7.4
251a3dc3edaSGreg Roach        'assets/js-1.7.2',
252a3dc3edaSGreg Roach        'themes/clouds/css-1.7.0',
253a3dc3edaSGreg Roach        'themes/colors/css-1.7.0',
254a3dc3edaSGreg Roach        'themes/fab/css-1.7.0',
255a3dc3edaSGreg Roach        'themes/minimal/css-1.7.0',
256a3dc3edaSGreg Roach        'themes/webtrees/css-1.7.0',
257a3dc3edaSGreg Roach        'themes/xenea/css-1.7.0',
258a3dc3edaSGreg Roach        // Removed in 1.7.5
259a3dc3edaSGreg Roach        'themes/clouds/css-1.7.4',
260a3dc3edaSGreg Roach        'themes/colors/css-1.7.4',
261a3dc3edaSGreg Roach        'themes/fab/css-1.7.4',
262a3dc3edaSGreg Roach        'themes/minimal/css-1.7.4',
263a3dc3edaSGreg Roach        'themes/webtrees/css-1.7.4',
264a3dc3edaSGreg Roach        'themes/xenea/css-1.7.4',
265a3dc3edaSGreg Roach        // Removed in 1.7.7
266a3dc3edaSGreg Roach        'assets/js-1.7.4',
267a3dc3edaSGreg Roach        // Removed in 1.7.8
268a3dc3edaSGreg Roach        'themes/clouds/css-1.7.5',
269a3dc3edaSGreg Roach        'themes/colors/css-1.7.5',
270a3dc3edaSGreg Roach        'themes/fab/css-1.7.5',
271a3dc3edaSGreg Roach        'themes/minimal/css-1.7.5',
272a3dc3edaSGreg Roach        'themes/webtrees/css-1.7.5',
273a3dc3edaSGreg Roach        'themes/xenea/css-1.7.5',
274a3dc3edaSGreg Roach        // Removed in 2.0.0
275a3dc3edaSGreg Roach        'action.php',
276a3dc3edaSGreg Roach        'addmedia.php',
277a3dc3edaSGreg Roach        'addmin.php',
278a3dc3edaSGreg Roach        'admin_media.php',
279a3dc3edaSGreg Roach        'admin_media_upload.php',
280a3dc3edaSGreg Roach        'admin_module_blocks.php',
281a3dc3edaSGreg Roach        'admin_module_charts.php',
282a3dc3edaSGreg Roach        'admin_module_menus.php',
283a3dc3edaSGreg Roach        'admin_module_reports.php',
284a3dc3edaSGreg Roach        'admin_module_sidebar.php',
285a3dc3edaSGreg Roach        'admin_module_tabs.php',
286a3dc3edaSGreg Roach        'admin_modules.php',
287a3dc3edaSGreg Roach        'admin_pgv_to_wt.php',
288a3dc3edaSGreg Roach        'admin_site_access.php',
289a3dc3edaSGreg Roach        'admin_site_change.php',
290a3dc3edaSGreg Roach        'admin_site_clean.php',
291a3dc3edaSGreg Roach        'admin_site_config.php',
292a3dc3edaSGreg Roach        'admin_site_info.php',
293a3dc3edaSGreg Roach        'admin_site_logs.php',
294a3dc3edaSGreg Roach        'admin_site_merge.php',
295a3dc3edaSGreg Roach        'admin_site_readme.php',
296a3dc3edaSGreg Roach        'admin_site_upgrade.php',
297a3dc3edaSGreg Roach        'admin_trees_check.php',
298a3dc3edaSGreg Roach        'admin_trees_config.php',
299a3dc3edaSGreg Roach        'admin_trees_download.php',
300a3dc3edaSGreg Roach        'admin_trees_duplicates.php',
301a3dc3edaSGreg Roach        'admin_trees_export.php',
302a3dc3edaSGreg Roach        'admin_trees_manage.php',
303a3dc3edaSGreg Roach        'admin_trees_merge.php',
304a3dc3edaSGreg Roach        'admin_trees_places.php',
305a3dc3edaSGreg Roach        'admin_trees_renumber.php',
306a3dc3edaSGreg Roach        'admin_trees_unconnected.php',
307a3dc3edaSGreg Roach        'admin_users.php',
308a3dc3edaSGreg Roach        'admin_users_bulk.php',
309a3dc3edaSGreg Roach        'ancestry.php',
310a3dc3edaSGreg Roach        'app/Controller',
311a3dc3edaSGreg Roach        'app/HitCounter.php',
312a3dc3edaSGreg Roach        'app/Module/ClippingsCart/ClippingsCartController.php',
313a3dc3edaSGreg Roach        'app/Module/FamiliesSidebarModule.php',
314a3dc3edaSGreg Roach        'app/Module/FamilyTreeFavorites',
315a3dc3edaSGreg Roach        'app/Module/GoogleMaps',
316a3dc3edaSGreg Roach        'app/Module/IndividualSidebarModule.php',
317a3dc3edaSGreg Roach        'app/Module/PageMenuModule.php',
31880536c2dSGreg Roach        'app/Query',
319a3dc3edaSGreg Roach        'app/SpecialChars',
320a3dc3edaSGreg Roach        'assets/js-1.7.7',
321a3dc3edaSGreg Roach        'assets/js-1.7.9',
322a3dc3edaSGreg Roach        'autocomplete.php',
323a3dc3edaSGreg Roach        'block_edit.php',
324a3dc3edaSGreg Roach        'branches.php',
325a3dc3edaSGreg Roach        'calendar.php',
326a3dc3edaSGreg Roach        'compact.php',
327a3dc3edaSGreg Roach        'data/html_purifier_cache',
328a3dc3edaSGreg Roach        'descendancy.php',
329a3dc3edaSGreg Roach        'editnews.php',
330a3dc3edaSGreg Roach        'edituser.php',
331a3dc3edaSGreg Roach        'edit_changes.php',
332a3dc3edaSGreg Roach        'edit_interface.php',
333a3dc3edaSGreg Roach        'expand_view.php',
334a3dc3edaSGreg Roach        'familybook.php',
335a3dc3edaSGreg Roach        'famlist.php',
336a3dc3edaSGreg Roach        'fanchart.php',
337a3dc3edaSGreg Roach        'find.php',
338a3dc3edaSGreg Roach        'help_text.php',
339a3dc3edaSGreg Roach        'hourglass.php',
340a3dc3edaSGreg Roach        'hourglass_ajax.php',
341a3dc3edaSGreg Roach        'import.php',
342a3dc3edaSGreg Roach        'includes',
343a3dc3edaSGreg Roach        'index_edit.php',
344a3dc3edaSGreg Roach        'indilist.php',
345a3dc3edaSGreg Roach        'inverselink.php',
346a3dc3edaSGreg Roach        'lifespan.php',
347a3dc3edaSGreg Roach        'login.php',
348a3dc3edaSGreg Roach        'logout.php',
349a3dc3edaSGreg Roach        'mediafirewall.php',
350a3dc3edaSGreg Roach        'medialist.php',
351a3dc3edaSGreg Roach        'message.php',
352a3dc3edaSGreg Roach        'module.php',
35349a243cbSGreg Roach        'modules_v3',
354a3dc3edaSGreg Roach        'notelist.php',
355a3dc3edaSGreg Roach        'packages',
356a3dc3edaSGreg Roach        'pedigree.php',
357a3dc3edaSGreg Roach        'relationship.php',
358a3dc3edaSGreg Roach        'repolist.php',
359a3dc3edaSGreg Roach        'reportengine.php',
360a3dc3edaSGreg Roach        'search.php',
361a3dc3edaSGreg Roach        'search_advanced.php',
362a3dc3edaSGreg Roach        'site-offline.php',
363a3dc3edaSGreg Roach        'site-unavailable.php',
364a3dc3edaSGreg Roach        'sourcelist.php',
365a3dc3edaSGreg Roach        'statistics.php',
366a3dc3edaSGreg Roach        'statisticsplot.php',
367a3dc3edaSGreg Roach        'themes/_administration',
368a3dc3edaSGreg Roach        'themes/_custom',
369a3dc3edaSGreg Roach        'themes/clouds/css-1.7.8',
370a3dc3edaSGreg Roach        'themes/clouds/jquery-ui-1.11.2',
371a3dc3edaSGreg Roach        'themes/colors/css-1.7.8',
372a3dc3edaSGreg Roach        'themes/colors/jquery-ui-1.11.2',
373a3dc3edaSGreg Roach        'themes/fab/css-1.7.8',
374a3dc3edaSGreg Roach        'themes/fab/jquery-ui-1.11.2',
375a3dc3edaSGreg Roach        'themes/minimal/css-1.7.8',
376a3dc3edaSGreg Roach        'themes/minimal/jquery-ui-1.11.2',
377a3dc3edaSGreg Roach        'themes/webtrees/css-1.7.8',
378a3dc3edaSGreg Roach        'themes/webtrees/jquery-ui-1.11.2',
379a3dc3edaSGreg Roach        'themes/xenea/css-1.7.8',
380a3dc3edaSGreg Roach        'themes/xenea/jquery-ui-1.11.2',
381a3dc3edaSGreg Roach        'timeline.php',
382a3dc3edaSGreg Roach    ];
383a3dc3edaSGreg Roach
384a3dc3edaSGreg Roach    /**
385a3dc3edaSGreg Roach     * Delete files and folders that belonged to an earlier version of webtrees.
386a3dc3edaSGreg Roach     * Return a list of those that we could not delete.
387a3dc3edaSGreg Roach     *
388a3dc3edaSGreg Roach     * @param Filesystem $filesystem
389a3dc3edaSGreg Roach     *
390a3dc3edaSGreg Roach     * @return array
391a3dc3edaSGreg Roach     */
392a3dc3edaSGreg Roach    public function deleteOldWebtreesFiles(Filesystem $filesystem): array
393a3dc3edaSGreg Roach    {
394a3dc3edaSGreg Roach        $paths_to_delete = [];
395a3dc3edaSGreg Roach
396a3dc3edaSGreg Roach        foreach (self::OLD_PATHS as $path) {
397a3dc3edaSGreg Roach            if (!$this->deleteFileOrFolder($filesystem, $path)) {
398a3dc3edaSGreg Roach                $paths_to_delete[] = $path;
399a3dc3edaSGreg Roach            }
400a3dc3edaSGreg Roach        }
401a3dc3edaSGreg Roach
402a3dc3edaSGreg Roach        return $paths_to_delete;
403a3dc3edaSGreg Roach    }
404a3dc3edaSGreg Roach
405a3dc3edaSGreg Roach    /**
406a3dc3edaSGreg Roach     * Delete old cache files.
407a3dc3edaSGreg Roach     *
408a3dc3edaSGreg Roach     * @param Filesystem $filesystem
409c61566f9SGreg Roach     * @param string     $path
410c61566f9SGreg Roach     * @param int        $max_age    Seconds
411c7ff4153SGreg Roach     *
412c7ff4153SGreg Roach     * @return void
413a3dc3edaSGreg Roach     */
414c61566f9SGreg Roach    public function deleteOldFiles(Filesystem $filesystem, string $path, int $max_age)
415a3dc3edaSGreg Roach    {
416c61566f9SGreg Roach        $list = $filesystem->listContents($path, true);
417a3dc3edaSGreg Roach
418*4459dc9aSGreg Roach        $timestamp = Carbon::now()->unix();
419ad98d39dSGreg Roach
420a3dc3edaSGreg Roach        foreach ($list as $metadata) {
421ad98d39dSGreg Roach            if ($metadata['timestamp'] ?? $timestamp < $timestamp - $max_age) {
422a3dc3edaSGreg Roach                $this->deleteFileOrFolder($filesystem, $metadata['path']);
423a3dc3edaSGreg Roach            }
424a3dc3edaSGreg Roach        }
425a3dc3edaSGreg Roach    }
426a3dc3edaSGreg Roach
427a3dc3edaSGreg Roach    /**
428a3dc3edaSGreg Roach     * @param int $max_age_in_seconds
429c7ff4153SGreg Roach     *
430c7ff4153SGreg Roach     * @return void
431a3dc3edaSGreg Roach     */
432a3dc3edaSGreg Roach    public function deleteOldLogs(int $max_age_in_seconds)
433a3dc3edaSGreg Roach    {
434ca52a408SGreg Roach        $timestamp = Carbon::now()->subSeconds($max_age_in_seconds);
435ca52a408SGreg Roach
436e5c19fcdSGreg Roach        DB::table('log')
437e5c19fcdSGreg Roach            ->whereIn('log_type', ['error', 'media'])
438ca52a408SGreg Roach            ->where('log_time', '<', $timestamp)
439e5c19fcdSGreg Roach            ->delete();
440a3dc3edaSGreg Roach    }
441a3dc3edaSGreg Roach
442a3dc3edaSGreg Roach    /**
443a3dc3edaSGreg Roach     * @param int $max_age_in_seconds
444c7ff4153SGreg Roach     *
445c7ff4153SGreg Roach     * @return void
446a3dc3edaSGreg Roach     */
447a3dc3edaSGreg Roach    public function deleteOldSessions(int $max_age_in_seconds)
448a3dc3edaSGreg Roach    {
449ca52a408SGreg Roach        $timestamp = Carbon::now()->subSeconds($max_age_in_seconds);
450ca52a408SGreg Roach
451e5c19fcdSGreg Roach        DB::table('session')
452ca52a408SGreg Roach            ->where('session_time', '<', $timestamp)
453e5c19fcdSGreg Roach            ->delete();
454a3dc3edaSGreg Roach    }
455a3dc3edaSGreg Roach
456a3dc3edaSGreg Roach    /**
457a3dc3edaSGreg Roach     * Delete a file or folder, if we can.
458a3dc3edaSGreg Roach     *
459a3dc3edaSGreg Roach     * @param Filesystem $filesystem
460a3dc3edaSGreg Roach     * @param string     $path
461a3dc3edaSGreg Roach     *
462a3dc3edaSGreg Roach     * @return bool
463a3dc3edaSGreg Roach     */
464a3dc3edaSGreg Roach    private function deleteFileOrFolder(Filesystem $filesystem, string $path): bool
465a3dc3edaSGreg Roach    {
466a3dc3edaSGreg Roach        if ($filesystem->has($path)) {
467a3dc3edaSGreg Roach            try {
468a3dc3edaSGreg Roach                $metadata = $filesystem->getMetadata($path);
469a3dc3edaSGreg Roach
470a3dc3edaSGreg Roach                if ($metadata['type'] === 'dir') {
471a3dc3edaSGreg Roach                    $filesystem->deleteDir($path);
472a3dc3edaSGreg Roach                }
473a3dc3edaSGreg Roach
474a3dc3edaSGreg Roach                if ($metadata['type'] === 'file') {
475a3dc3edaSGreg Roach                    $filesystem->delete($path);
476a3dc3edaSGreg Roach                }
477a3dc3edaSGreg Roach            } catch (Exception $ex) {
478a3dc3edaSGreg Roach                return false;
479a3dc3edaSGreg Roach            }
480a3dc3edaSGreg Roach        }
481a3dc3edaSGreg Roach
482a3dc3edaSGreg Roach        return true;
483a3dc3edaSGreg Roach    }
484a3dc3edaSGreg Roach}
485