ion-triangle"> ' . sprintf(__('Can\'t move %1$s to %2$s', 'duplicator-pro'), esc_html($path), DUPLICATOR_PRO_SSDIR_PATH_INSTALLER) . ''; } } } } /** * Get file list to store * * @return array */ public static function getStoredMigrationLists() { if (($migrationData = self::getMigrationData()) == false) { $filesToCheck = array(); } else { $filesToCheck = array( $migrationData->installerLog => __('Installer log', 'duplicator-pro'), $migrationData->installerBootLog => __('Installer boot log', 'duplicator-pro'), $migrationData->origFileFolderPath => __('Original files folder', 'duplicator-pro'), ); } $result = array(); foreach ($filesToCheck as $path => $label) { $storedPath = DUPLICATOR_PRO_SSDIR_PATH_INSTALLER . '/' . basename($path); if (!file_exists($storedPath)) { continue; } $result[$storedPath] = $label; } return $result; } /** * Check if exist file to remove * * @return bool */ public static function haveFileToClean() { return count(self::checkInstallerFilesList()) > 0; } /** * Gets a list of all the installer files and directory by name and full path * * @remarks * FILES: installer.php, installer-backup.php, dup-installer-bootlog__[HASH].txt * DIRS: dup-installer * Last set is for lazy developer cleanup files that a developer may have * accidentally left around lets be proactive for the user just in case. * * @return string[] file names */ public static function getGenericInstallerFiles() { return array( 'installer.php', '[HASH]installer-backup.php', 'dup-installer', 'dup-installer[HASH]', 'dup-installer-bootlog__[HASH].txt', '[HASH]_archive.zip|daf', ); } /** * Get installer files list * * @return string[] */ public static function checkInstallerFilesList() { $migrationData = self::getMigrationData(); $foldersToChkeck = array( SnapIO::safePathTrailingslashit(ABSPATH), SnapWP::getHomePath(), ); $result = array(); if (!empty($migrationData)) { if ( file_exists($migrationData->archivePath) && !DUP_PRO_Archive::isBackupPathChild($migrationData->archivePath) && !PackageImporter::isImportPath($migrationData->archivePath) && !RecoveryPackage::isRecoverPath($migrationData->archivePath) && !StoragesUtil::isLocalStorageChildPath($migrationData->archivePath) ) { $result[] = $migrationData->archivePath; } if ( file_exists($migrationData->installerPath) && self::isInstallerFile($migrationData->installerPath) && !DUP_PRO_Archive::isBackupPathChild($migrationData->installerPath) && !RecoveryPackage::isRecoverPath($migrationData->installerPath) && !StoragesUtil::isLocalStorageChildPath($migrationData->installerPath) ) { $result[] = $migrationData->installerPath; } if (file_exists($migrationData->installerBootLog)) { $result[] = $migrationData->installerBootLog; } if (file_exists($migrationData->dupInstallerPath)) { $result[] = $migrationData->dupInstallerPath; } } foreach ($foldersToChkeck as $folder) { $result = array_merge($result, SnapIO::regexGlob($folder, array( 'regexFile' => array( DUPLICATOR_PRO_ARCHIVE_REGEX_PATTERN, DUPLICATOR_PRO_INSTALLER_REGEX_PATTERN, DUPLICATOR_PRO_DUP_INSTALLER_BOOTLOG_REGEX_PATTERN, DUPLICATOR_PRO_DUP_INSTALLER_OWRPARAM_REGEX_PATTERN, ), 'regexFolder' => array(DUPLICATOR_PRO_DUP_INSTALLER_FOLDER_REGEX_PATTERN), ))); } $result = array_map(array('\\Duplicator\\Libs\\Snap\\SnapIO', 'safePathUntrailingslashit'), $result); return array_unique($result); } /** * Check if file is installer file * * @param string $path path to check * * @return bool true if the file at current path is the installer file */ public static function isInstallerFile($path) { if (!is_file($path) || !is_array($last5Lines = SnapIO::getLastLinesOfFile($path, 5)) || empty($last5Lines)) { return false; } return strpos(implode("", $last5Lines), "DUPLICATOR_PRO_INSTALLER_EOF") !== false; } /** * Clean installer files * * @param bool $deleteCleanInstallReportOption Delete clean install report option * @param int $fileTimeDelay File time delay * * @return array Clean result */ public static function cleanMigrationFiles($deleteCleanInstallReportOption = true, $fileTimeDelay = 0) { $cleanList = self::checkInstallerFilesList(); $result = array(); foreach ($cleanList as $path) { $success = false; try { if ($fileTimeDelay <= 0 || time() - filectime($path) > $fileTimeDelay) { $success = (SnapIO::rrmdir($path) !== false); } else { // The file does not even need to be removed yet $success = true; } } catch (Exception $ex) { $success = false; } catch (Error $ex) { $success = false; } $result[$path] = $success; } if ($deleteCleanInstallReportOption) { delete_option(self::CLEAN_INSTALL_REPORT_OPTION); } return $result; } /** * Recalculate active schedules next run time * * @return void */ public static function updateNextSchedules() { $schedules = DUP_PRO_Schedule_Entity::get_active(); foreach ($schedules as $schedule) { $schedule->updateNextRuntime(); } } }