1a3dc3edaSGreg Roach<?php 23976b470SGreg Roach 3a3dc3edaSGreg Roach/** 4a3dc3edaSGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 6a3dc3edaSGreg Roach * This program is free software: you can redistribute it and/or modify 7a3dc3edaSGreg Roach * it under the terms of the GNU General Public License as published by 8a3dc3edaSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a3dc3edaSGreg Roach * (at your option) any later version. 10a3dc3edaSGreg Roach * This program is distributed in the hope that it will be useful, 11a3dc3edaSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a3dc3edaSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a3dc3edaSGreg Roach * GNU General Public License for more details. 14a3dc3edaSGreg Roach * You should have received a copy of the GNU General Public License 15a3dc3edaSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16a3dc3edaSGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 20a3dc3edaSGreg Roachnamespace Fisharebest\Webtrees\Services; 21a3dc3edaSGreg Roach 22a3dc3edaSGreg Roachuse Exception; 234459dc9aSGreg Roachuse Fisharebest\Webtrees\Carbon; 24e5c19fcdSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 25e37157fcSGreg Roachuse League\Flysystem\FilesystemInterface; 26a3dc3edaSGreg Roach 27a3dc3edaSGreg Roach/** 28a3dc3edaSGreg Roach * Clean up old data, files and folders. 29a3dc3edaSGreg Roach */ 30a3dc3edaSGreg Roachclass HousekeepingService 31a3dc3edaSGreg Roach{ 32a3dc3edaSGreg Roach // This is a list of old files and directories, from earlier versions of webtrees. 33a3dc3edaSGreg Roach // git diff 1.7.9..master --name-status | grep ^D 3416d6367aSGreg Roach private const OLD_PATHS = [ 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', 51f397d0fdSGreg Roach //'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', 56f397d0fdSGreg Roach //'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 'library', 214a3dc3edaSGreg Roach 'save.php', 215a3dc3edaSGreg Roach 'themes/clouds/css-1.6.2', 216a3dc3edaSGreg Roach 'themes/clouds/templates', 217a3dc3edaSGreg Roach 'themes/clouds/header.php', 218a3dc3edaSGreg Roach 'themes/clouds/footer.php', 219a3dc3edaSGreg Roach 'themes/colors/css-1.6.2', 220a3dc3edaSGreg Roach 'themes/colors/templates', 221a3dc3edaSGreg Roach 'themes/colors/header.php', 222a3dc3edaSGreg Roach 'themes/colors/footer.php', 223a3dc3edaSGreg Roach 'themes/fab/css-1.6.2', 224a3dc3edaSGreg Roach 'themes/fab/templates', 225a3dc3edaSGreg Roach 'themes/fab/header.php', 226a3dc3edaSGreg Roach 'themes/fab/footer.php', 227a3dc3edaSGreg Roach 'themes/minimal/css-1.6.2', 228a3dc3edaSGreg Roach 'themes/minimal/templates', 229a3dc3edaSGreg Roach 'themes/minimal/header.php', 230a3dc3edaSGreg Roach 'themes/minimal/footer.php', 231a3dc3edaSGreg Roach 'themes/webtrees/css-1.6.2', 232a3dc3edaSGreg Roach 'themes/webtrees/templates', 233a3dc3edaSGreg Roach 'themes/webtrees/header.php', 234a3dc3edaSGreg Roach 'themes/webtrees/footer.php', 235a3dc3edaSGreg Roach 'themes/xenea/css-1.6.2', 236a3dc3edaSGreg Roach 'themes/xenea/templates', 237a3dc3edaSGreg Roach 'themes/xenea/header.php', 238a3dc3edaSGreg Roach 'themes/xenea/footer.php', 239a3dc3edaSGreg Roach // Removed in 1.7.2 240a3dc3edaSGreg Roach 'assets/js-1.7.0', 241a3dc3edaSGreg Roach // Removed in 1.7.4 242a3dc3edaSGreg Roach 'assets/js-1.7.2', 243a3dc3edaSGreg Roach 'themes/clouds/css-1.7.0', 244a3dc3edaSGreg Roach 'themes/colors/css-1.7.0', 245a3dc3edaSGreg Roach 'themes/fab/css-1.7.0', 246a3dc3edaSGreg Roach 'themes/minimal/css-1.7.0', 247a3dc3edaSGreg Roach 'themes/webtrees/css-1.7.0', 248a3dc3edaSGreg Roach 'themes/xenea/css-1.7.0', 249a3dc3edaSGreg Roach // Removed in 1.7.5 250a3dc3edaSGreg Roach 'themes/clouds/css-1.7.4', 251a3dc3edaSGreg Roach 'themes/colors/css-1.7.4', 252a3dc3edaSGreg Roach 'themes/fab/css-1.7.4', 253a3dc3edaSGreg Roach 'themes/minimal/css-1.7.4', 254a3dc3edaSGreg Roach 'themes/webtrees/css-1.7.4', 255a3dc3edaSGreg Roach 'themes/xenea/css-1.7.4', 256a3dc3edaSGreg Roach // Removed in 1.7.7 257a3dc3edaSGreg Roach 'assets/js-1.7.4', 258a3dc3edaSGreg Roach // Removed in 1.7.8 259a3dc3edaSGreg Roach 'themes/clouds/css-1.7.5', 260a3dc3edaSGreg Roach 'themes/colors/css-1.7.5', 261a3dc3edaSGreg Roach 'themes/fab/css-1.7.5', 262a3dc3edaSGreg Roach 'themes/minimal/css-1.7.5', 263a3dc3edaSGreg Roach 'themes/webtrees/css-1.7.5', 264a3dc3edaSGreg Roach 'themes/xenea/css-1.7.5', 265a3dc3edaSGreg Roach // Removed in 2.0.0 266a3dc3edaSGreg Roach 'action.php', 267a3dc3edaSGreg Roach 'addmedia.php', 268a3dc3edaSGreg Roach 'addmin.php', 269a3dc3edaSGreg Roach 'admin_media.php', 270a3dc3edaSGreg Roach 'admin_media_upload.php', 271a3dc3edaSGreg Roach 'admin_module_blocks.php', 272a3dc3edaSGreg Roach 'admin_module_charts.php', 273a3dc3edaSGreg Roach 'admin_module_menus.php', 274a3dc3edaSGreg Roach 'admin_module_reports.php', 275a3dc3edaSGreg Roach 'admin_module_sidebar.php', 276a3dc3edaSGreg Roach 'admin_module_tabs.php', 277a3dc3edaSGreg Roach 'admin_modules.php', 278a3dc3edaSGreg Roach 'admin_pgv_to_wt.php', 279a3dc3edaSGreg Roach 'admin_site_access.php', 280a3dc3edaSGreg Roach 'admin_site_change.php', 281a3dc3edaSGreg Roach 'admin_site_clean.php', 282a3dc3edaSGreg Roach 'admin_site_config.php', 283a3dc3edaSGreg Roach 'admin_site_info.php', 284a3dc3edaSGreg Roach 'admin_site_logs.php', 285a3dc3edaSGreg Roach 'admin_site_merge.php', 286a3dc3edaSGreg Roach 'admin_site_readme.php', 287a3dc3edaSGreg Roach 'admin_site_upgrade.php', 288a3dc3edaSGreg Roach 'admin_trees_check.php', 289a3dc3edaSGreg Roach 'admin_trees_config.php', 290a3dc3edaSGreg Roach 'admin_trees_download.php', 291a3dc3edaSGreg Roach 'admin_trees_duplicates.php', 292a3dc3edaSGreg Roach 'admin_trees_export.php', 293a3dc3edaSGreg Roach 'admin_trees_manage.php', 294a3dc3edaSGreg Roach 'admin_trees_merge.php', 295a3dc3edaSGreg Roach 'admin_trees_places.php', 296a3dc3edaSGreg Roach 'admin_trees_renumber.php', 297a3dc3edaSGreg Roach 'admin_trees_unconnected.php', 298a3dc3edaSGreg Roach 'admin_users.php', 299a3dc3edaSGreg Roach 'admin_users_bulk.php', 300a3dc3edaSGreg Roach 'ancestry.php', 301a3dc3edaSGreg Roach 'app/Controller', 302a3dc3edaSGreg Roach 'app/HitCounter.php', 303a3dc3edaSGreg Roach 'app/Module/ClippingsCart/ClippingsCartController.php', 304a3dc3edaSGreg Roach 'app/Module/FamiliesSidebarModule.php', 305a3dc3edaSGreg Roach 'app/Module/FamilyTreeFavorites', 306a3dc3edaSGreg Roach 'app/Module/GoogleMaps', 307a3dc3edaSGreg Roach 'app/Module/IndividualSidebarModule.php', 308a3dc3edaSGreg Roach 'app/Module/PageMenuModule.php', 30980536c2dSGreg Roach 'app/Query', 310a3dc3edaSGreg Roach 'app/SpecialChars', 311a3dc3edaSGreg Roach 'assets/js-1.7.7', 312a3dc3edaSGreg Roach 'assets/js-1.7.9', 313a3dc3edaSGreg Roach 'autocomplete.php', 314a3dc3edaSGreg Roach 'block_edit.php', 315a3dc3edaSGreg Roach 'branches.php', 316a3dc3edaSGreg Roach 'calendar.php', 317a3dc3edaSGreg Roach 'compact.php', 318a3dc3edaSGreg Roach 'data/html_purifier_cache', 319a3dc3edaSGreg Roach 'descendancy.php', 320a3dc3edaSGreg Roach 'editnews.php', 321a3dc3edaSGreg Roach 'edituser.php', 322a3dc3edaSGreg Roach 'edit_changes.php', 323a3dc3edaSGreg Roach 'edit_interface.php', 324a3dc3edaSGreg Roach 'expand_view.php', 325a3dc3edaSGreg Roach 'familybook.php', 326a3dc3edaSGreg Roach 'famlist.php', 327a3dc3edaSGreg Roach 'fanchart.php', 328a3dc3edaSGreg Roach 'find.php', 329a3dc3edaSGreg Roach 'help_text.php', 330a3dc3edaSGreg Roach 'hourglass.php', 331a3dc3edaSGreg Roach 'hourglass_ajax.php', 332a3dc3edaSGreg Roach 'import.php', 333a3dc3edaSGreg Roach 'includes', 334a3dc3edaSGreg Roach 'index_edit.php', 335a3dc3edaSGreg Roach 'indilist.php', 336a3dc3edaSGreg Roach 'inverselink.php', 337362b8464SGreg Roach 'language', 338a3dc3edaSGreg Roach 'lifespan.php', 339a3dc3edaSGreg Roach 'login.php', 340a3dc3edaSGreg Roach 'logout.php', 341a3dc3edaSGreg Roach 'mediafirewall.php', 342a3dc3edaSGreg Roach 'medialist.php', 343a3dc3edaSGreg Roach 'message.php', 344a3dc3edaSGreg Roach 'module.php', 34549a243cbSGreg Roach 'modules_v3', 346a3dc3edaSGreg Roach 'notelist.php', 347a3dc3edaSGreg Roach 'packages', 348a3dc3edaSGreg Roach 'pedigree.php', 349a3dc3edaSGreg Roach 'relationship.php', 350a3dc3edaSGreg Roach 'repolist.php', 351a3dc3edaSGreg Roach 'reportengine.php', 352a3dc3edaSGreg Roach 'search.php', 353a3dc3edaSGreg Roach 'search_advanced.php', 354a3dc3edaSGreg Roach 'site-offline.php', 355a3dc3edaSGreg Roach 'site-unavailable.php', 356a3dc3edaSGreg Roach 'sourcelist.php', 357a3dc3edaSGreg Roach 'statistics.php', 358a3dc3edaSGreg Roach 'statisticsplot.php', 359a3dc3edaSGreg Roach 'themes/_administration', 360a3dc3edaSGreg Roach 'themes/_custom', 361a3dc3edaSGreg Roach 'themes/clouds/css-1.7.8', 362a3dc3edaSGreg Roach 'themes/clouds/jquery-ui-1.11.2', 363a3dc3edaSGreg Roach 'themes/colors/css-1.7.8', 364a3dc3edaSGreg Roach 'themes/colors/jquery-ui-1.11.2', 365a3dc3edaSGreg Roach 'themes/fab/css-1.7.8', 366a3dc3edaSGreg Roach 'themes/fab/jquery-ui-1.11.2', 367a3dc3edaSGreg Roach 'themes/minimal/css-1.7.8', 368a3dc3edaSGreg Roach 'themes/minimal/jquery-ui-1.11.2', 369a3dc3edaSGreg Roach 'themes/webtrees/css-1.7.8', 370a3dc3edaSGreg Roach 'themes/webtrees/jquery-ui-1.11.2', 371a3dc3edaSGreg Roach 'themes/xenea/css-1.7.8', 372a3dc3edaSGreg Roach 'themes/xenea/jquery-ui-1.11.2', 373a3dc3edaSGreg Roach 'timeline.php', 374a3dc3edaSGreg Roach ]; 375a3dc3edaSGreg Roach 376a3dc3edaSGreg Roach /** 377a3dc3edaSGreg Roach * Delete files and folders that belonged to an earlier version of webtrees. 378a3dc3edaSGreg Roach * Return a list of those that we could not delete. 379a3dc3edaSGreg Roach * 380e37157fcSGreg Roach * @param FilesystemInterface $filesystem 381a3dc3edaSGreg Roach * 382a3dc3edaSGreg Roach * @return array 383a3dc3edaSGreg Roach */ 384e37157fcSGreg Roach public function deleteOldWebtreesFiles(FilesystemInterface $filesystem): array 385a3dc3edaSGreg Roach { 386a3dc3edaSGreg Roach $paths_to_delete = []; 387a3dc3edaSGreg Roach 388a3dc3edaSGreg Roach foreach (self::OLD_PATHS as $path) { 389a3dc3edaSGreg Roach if (!$this->deleteFileOrFolder($filesystem, $path)) { 390a3dc3edaSGreg Roach $paths_to_delete[] = $path; 391a3dc3edaSGreg Roach } 392a3dc3edaSGreg Roach } 393a3dc3edaSGreg Roach 394a3dc3edaSGreg Roach return $paths_to_delete; 395a3dc3edaSGreg Roach } 396a3dc3edaSGreg Roach 397a3dc3edaSGreg Roach /** 398a3dc3edaSGreg Roach * Delete old cache files. 399a3dc3edaSGreg Roach * 400e37157fcSGreg Roach * @param FilesystemInterface $filesystem 401c61566f9SGreg Roach * @param string $path 402c61566f9SGreg Roach * @param int $max_age Seconds 403c7ff4153SGreg Roach * 404c7ff4153SGreg Roach * @return void 405a3dc3edaSGreg Roach */ 406e37157fcSGreg Roach public function deleteOldFiles(FilesystemInterface $filesystem, string $path, int $max_age): void 407a3dc3edaSGreg Roach { 408*e1357632SGreg Roach $threshold = Carbon::now()->unix() - $max_age; 409*e1357632SGreg Roach 410c61566f9SGreg Roach $list = $filesystem->listContents($path, true); 411a3dc3edaSGreg Roach 412a3dc3edaSGreg Roach foreach ($list as $metadata) { 413*e1357632SGreg Roach // The timestamp can be absent or false. 414*e1357632SGreg Roach $timestamp = $metadata['timestamp'] ?? false; 415*e1357632SGreg Roach 416*e1357632SGreg Roach if ($timestamp !== false && $timestamp < $threshold) { 417a3dc3edaSGreg Roach $this->deleteFileOrFolder($filesystem, $metadata['path']); 418a3dc3edaSGreg Roach } 419a3dc3edaSGreg Roach } 420a3dc3edaSGreg Roach } 421a3dc3edaSGreg Roach 422a3dc3edaSGreg Roach /** 423a3dc3edaSGreg Roach * @param int $max_age_in_seconds 424c7ff4153SGreg Roach * 425c7ff4153SGreg Roach * @return void 426a3dc3edaSGreg Roach */ 427e364afe4SGreg Roach public function deleteOldLogs(int $max_age_in_seconds): void 428a3dc3edaSGreg Roach { 429ca52a408SGreg Roach $timestamp = Carbon::now()->subSeconds($max_age_in_seconds); 430ca52a408SGreg Roach 431e5c19fcdSGreg Roach DB::table('log') 432e5c19fcdSGreg Roach ->whereIn('log_type', ['error', 'media']) 433ca52a408SGreg Roach ->where('log_time', '<', $timestamp) 434e5c19fcdSGreg Roach ->delete(); 435a3dc3edaSGreg Roach } 436a3dc3edaSGreg Roach 437a3dc3edaSGreg Roach /** 438a3dc3edaSGreg Roach * @param int $max_age_in_seconds 439c7ff4153SGreg Roach * 440c7ff4153SGreg Roach * @return void 441a3dc3edaSGreg Roach */ 442e364afe4SGreg Roach public function deleteOldSessions(int $max_age_in_seconds): void 443a3dc3edaSGreg Roach { 444ca52a408SGreg Roach $timestamp = Carbon::now()->subSeconds($max_age_in_seconds); 445ca52a408SGreg Roach 446e5c19fcdSGreg Roach DB::table('session') 447ca52a408SGreg Roach ->where('session_time', '<', $timestamp) 448e5c19fcdSGreg Roach ->delete(); 449a3dc3edaSGreg Roach } 450a3dc3edaSGreg Roach 451a3dc3edaSGreg Roach /** 452a3dc3edaSGreg Roach * Delete a file or folder, if we can. 453a3dc3edaSGreg Roach * 454e37157fcSGreg Roach * @param FilesystemInterface $filesystem 455a3dc3edaSGreg Roach * @param string $path 456a3dc3edaSGreg Roach * 457a3dc3edaSGreg Roach * @return bool 458a3dc3edaSGreg Roach */ 459e37157fcSGreg Roach private function deleteFileOrFolder(FilesystemInterface $filesystem, string $path): bool 460a3dc3edaSGreg Roach { 461a3dc3edaSGreg Roach if ($filesystem->has($path)) { 462a3dc3edaSGreg Roach try { 463a3dc3edaSGreg Roach $metadata = $filesystem->getMetadata($path); 464a3dc3edaSGreg Roach 465a3dc3edaSGreg Roach if ($metadata['type'] === 'dir') { 466a3dc3edaSGreg Roach $filesystem->deleteDir($path); 467a3dc3edaSGreg Roach } 468a3dc3edaSGreg Roach 469a3dc3edaSGreg Roach if ($metadata['type'] === 'file') { 470a3dc3edaSGreg Roach $filesystem->delete($path); 471a3dc3edaSGreg Roach } 472a3dc3edaSGreg Roach } catch (Exception $ex) { 473a3dc3edaSGreg Roach return false; 474a3dc3edaSGreg Roach } 475a3dc3edaSGreg Roach } 476a3dc3edaSGreg Roach 477a3dc3edaSGreg Roach return true; 478a3dc3edaSGreg Roach } 479a3dc3edaSGreg Roach} 480