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