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