if (basename($file) === 'index.php') { continue; } SnapIO::rrmdir($file); } } else { // Remove scan files that are 24 hours old $dir = DUPLICATOR_SSDIR_PATH_TMP . "/*_scan.json"; foreach (glob($dir) as $file) { if (filemtime($file) <= time() - Constants::TEMP_CLEANUP_SECONDS) { SnapIO::rrmdir($file); } } } // Clean up extras directory if it is still hanging around $extras_directory = SnapIO::safePath(DUPLICATOR_SSDIR_PATH_TMP) . '/extras'; if (file_exists($extras_directory)) { try { if (!SnapIO::rrmdir($extras_directory)) { throw new Exception('Failed to delete: ' . $extras_directory); } } catch (Exception $ex) { DupLog::trace("Couldn't recursively delete {$extras_directory}"); } } return true; } /** * Remove leftover partial archive files from the tmp directory * * @return void */ public static function purgeTempArchives(): void { foreach (['zip', 'daf'] as $extension) { $pattern = DUPLICATOR_SSDIR_PATH_TMP . "/*_archive.{$extension}.*"; $files = SnapIO::callWithPhpErrorCapture(static fn() => glob($pattern)); foreach ($files ?: [] as $path) { if (!SnapIO::unlink($path)) { DupLog::trace('Could not remove temporary archive: ' . $path); } } } } /** * Remove tmp directory entries older than the cleanup threshold * * @return void */ public static function safeTmpCleanup(): void { $files = SnapIO::callWithPhpErrorCapture(static fn() => glob(DUPLICATOR_SSDIR_PATH_TMP . '/*')); foreach ($files ?: [] as $path) { if (basename($path) === 'index.php' || !SnapIO::isOlderThan($path, Constants::TEMP_CLEANUP_SECONDS)) { continue; } if (!SnapIO::rrmdir($path)) { DupLog::trace('Could not remove temporary file: ' . $path); } } } /** * Get the type string for a package * * @param AbstractPackage $package The package * * @return string */ public static function getTypeString(AbstractPackage $package): string { $typeString = __('Manual', 'duplicator'); if ($package->template_id != -1) { $template = TemplateEntity::getById($package->template_id); if ($template !== false && !$template->is_manual) { $typeString = __('Template', 'duplicator') . ' ' . $template->name; } } switch ($package->getExecutionType()) { case AbstractPackage::EXECUTION_TYPE_AUTOTUNE: $typeString = __('AutoTune', 'duplicator'); break; case AbstractPackage::EXECUTION_TYPE_API: $typeString = __('API', 'duplicator'); break; } return (string) apply_filters('duplicator_package_type_string', $typeString, $package); } /** * Returns the Backup engine type string, thread mode included when the * engine has one (e.g. "ZipArchive | single thread") * * @param int $engineType Backup engine type * @param int $zipArchiveMode Zip archive mode * * @return string */ public static function getEngineTypeString(int $engineType, int $zipArchiveMode): string { return self::joinLabelParts(self::getEngineTypeLabelParts($engineType, $zipArchiveMode)); } /** * Returns the Backup engine label split into the engine name and its * thread mode; the mode is empty for engines without one * * @param int $engineType Backup engine type * @param int $zipArchiveMode Zip archive mode * * @return array{label: string, mode: string} */ public static function getEngineTypeLabelParts(int $engineType, int $zipArchiveMode): array { switch ($engineType) { case PackageArchive::BUILD_MODE_SHELL_EXEC: case PackageArchive::BUILD_MODE_DUP_ARCHIVE: return [ 'label' => OptionsManager::getInstance()->getValueLabel(ArchiveEngineRule::OPTION_KEY, $engineType), 'mode' => '', ]; case PackageArchive::BUILD_MODE_ZIP_ARCHIVE: return [ 'label' => OptionsManager::getInstance()->getValueLabel(ArchiveEngineRule::OPTION_KEY, $engineType), 'mode' => self::getThreadModeLabel($zipArchiveMode !== PackageArchive::ZIP_MODE_SINGLE_THREAD), ]; default: return [ 'label' => __('Unknown', 'duplicator'), 'mode' => '', ]; } } /** * Returns the database build mode label, thread mode included for the PHP * dump (e.g. "PHP Code | multi-thread") * * @param string $buildMode Database build mode, enum WpDbUtils::BUILD_MODE_* * * @return string */ public static function getDbBuildModeLabel(string $buildMode): string { return self::joinLabelParts(self::getDbBuildModeLabelParts($buildMode)); } /** * Returns the database build mode label split into the dump engine name * and its thread mode; the mode is empty for mysqldump * * @param string $buildMode Database build mode, enum WpDbUtils::BUILD_MODE_* * * @return array{label: string, mode: string} */ public static function getDbBuildModeLabelParts(string $buildMode): array { $optionsManager = OptionsManager::getInstance(); switch ($buildMode) { case WpDbUtils::BUILD_MODE_MYSQLDUMP: return [ 'label' => $optionsManager->getValueLabel(DbDumpEngineRule::OPTION_KEY, DbDumpEngineRule::VALUE_MYSQLDUMP), 'mode' => '', ]; case WpDbUtils::BUILD_MODE_PHP_SINGLE_THREAD: return [ 'label' => $optionsManager->getValueLabel(DbDumpEngineRule::OPTION_KEY, DbDumpEngineRule::VALUE_PHP), 'mode' => self::getThreadModeLabel(false), ]; case WpDbUtils::BUILD_MODE_PHP_MULTI_THREAD: return [ 'label' => $optionsManager->getValueLabel(DbDumpEngineRule::OPTION_KEY, DbDumpEngineRule::VALUE_PHP), 'mode' => self::getThreadModeLabel(true), ]; default: return [ 'label' => __('Unknown', 'duplicator'), 'mode' => '', ]; } } /** * Returns a human readable duration, or N/A for a negative value (nothing recorded) * * @param float $seconds Duration in seconds * * @return string */ public static function getDurationLabel(float $seconds): string { if ($seconds < 0) { return __('N/A', 'duplicator'); } // Sub-second durations keep one decimal so they don't collapse to zero if ($seconds < 1) { return sprintf(__('%.1f sec', 'duplicator'), $seconds); } return SnapString::formatHumanReadableDuration($seconds, 0); } /** * Returns the thread mode label * * @param bool $multiThread True for the multi-thread mode * * @return string */ private static function getThreadModeLabel(bool $multiThread): string { return $multiThread ? __('multi-thread', 'duplicator') : __('single thread', 'duplicator'); } /** * Joins a label and its optional mode with the composite value separator * * @param array{label: string, mode: string} $parts Label parts * * @return string */ private static function joinLabelParts(array $parts): string { return strlen($parts['mode']) > 0 ? $parts['label'] . ' | ' . $parts['mode'] : $parts['label']; } /** * Returns the Backup engine type string resolved from the frozen build * options; unknown when the options were never frozen (legacy Backups or * failures before the backup start). * * @param AbstractPackage $package The Backup * * @return string */ public static function getPackageEngineTypeString(AbstractPackage $package): string { $options = $package->getBuildOptions(); if ($options === null) { return __('Unknown', 'duplicator'); } return self::getEngineTypeString($options->getArchiveEngine(), $options->getZipArchiveMode()); } /** * Returns the database build mode resolved from the frozen build options; empty when * the options were never frozen (legacy Backups or failures before the backup start), * because the present global setting is not what built the Backup. * * @param AbstractPackage $package The Backup * * @return string enum WpDbUtils::BUILD_MODE_*, empty when nothing was frozen */ public static function getPackageDbBuildMode(AbstractPackage $package): string { $options = $package->getBuildOptions(); if ($options === null) { return ''; } return $options->getDbBuildMode(); } /** * Returns an array with stats about the orphaned files * * @return string[] The full path of the orphaned file */ public static function getOrphanedPackageFiles(): array { $global = GlobalEntity::getInstance(); $orphans = []; $numPackages = DupPackage::countByStatus([], [DupPackage::getType()]); $numPerPage = 100; $pages = floor($numPackages / $numPerPage) + 1; $skipStart = ['dup_pro']; for ($page = 0; $page < $pages; $page++) { $offset = $page * $numPerPage; $pagePackages = DupPackage::getRowByStatus( [], $numPerPage, $offset, '`id` ASC', [DupPackage::getType()] ); foreach ($pagePackages as $cPack) { $skipStart[] = $cPack->name . '_' . $cPack->hash; } } $pagePackages = null; $fileTimeSkipInSec = ( max( Constants::DEFAULT_MAX_PACKAGE_RUNTIME_IN_MIN, $global->getMaxPackageRuntime() ) + Constants::ORPAHN_CLEANUP_DELAY_MAX_PACKAGE_RUNTIME ) * 60; // Only scan backup directory - log files are excluded as they're preserved for Activity Log foreach ( [DUPLICATOR_SSDIR_PATH] as $rootPathToCheck ) { if (file_exists($rootPathToCheck) && ($handle = opendir($rootPathToCheck)) !== false) { while (false !== ($fileName = readdir($handle))) { if ($fileName == '.' || $fileName == '..') { continue; } $fileFullPath = $rootPathToCheck . '/' . $fileName; if (is_dir($fileFullPath)) { continue; } if (time() - filemtime($fileFullPath) < $fileTimeSkipInSec) { // file younger than 2 hours skip for security continue; } if (!preg_match(DUPLICATOR_FULL_GEN_BACKUP_FILE_REGEX_PATTERN, $fileName)) { continue; } foreach ($skipStart as $skip) { if (strpos($fileName, $skip) === 0) { continue 2; } } $orphans[] = $fileFullPath; } closedir($handle); } } return $orphans; } /** * Returns an array with stats about the orphaned files * * @return array{size:int,count:int} The total count and file size of orphaned files */ public static function getOrphanedPackageInfo(): array { $files = self::getOrphanedPackageFiles(); $info = []; $info['size'] = 0; $info['count'] = 0; if (count($files)) { foreach ($files as $path) { $get_size = @filesize($path); if ($get_size > 0) { $info['size'] += $get_size; $info['count']++; } } } return $info; } /** * Cleanup old log files based on Activity Log retention period * * @return array{deleted_count:int,freed_size:int} Statistics about deleted files */ public static function cleanupOldLogFiles(): array { $result = [ 'deleted_count' => 0, 'freed_size' => 0, ]; $dGlobal = DynamicGlobalEntity::getInstance(); $retentionSeconds = $dGlobal->getValInt('activity_log_retention'); // If retention is 0 or less, keep all logs forever if ($retentionSeconds <= 0) { DupLog::trace("Log cleanup: Retention disabled (value: {$retentionSeconds}), keeping all log files"); return $result; } $expirationTimestamp = time() - $retentionSeconds; $logsPath = DUPLICATOR_LOGS_PATH; if (!file_exists($logsPath) || !is_dir($logsPath)) { DupLog::trace("Log cleanup: Logs directory does not exist: {$logsPath}"); return $result; } $retentionDays = round($retentionSeconds / DAY_IN_SECONDS); DupLog::trace("Log cleanup: Scanning for files older than {$retentionDays} days ({$retentionSeconds} seconds) in {$logsPath}"); $globFiles = glob(SnapIO::safePath(SnapIO::untrailingslashit($logsPath) . "/*_log.txt")); if ($globFiles === false) { DupLog::trace("Log cleanup: Failed to scan logs directory: {$logsPath}"); return $result; } foreach ($globFiles as $filePath) { $fileTime = @filemtime($filePath); if ($fileTime === false) { DupLog::trace("Log cleanup: Failed to get modification time for: " . basename($filePath)); continue; } if ($fileTime < $expirationTimestamp) { $fileSize = @filesize($filePath); if (SnapIO::unlink($filePath)) { $result['deleted_count']++; $result['freed_size'] += ($fileSize !== false ? $fileSize : 0); DupLog::trace("Log cleanup: Deleted expired log file: " . basename($filePath)); } else { DupLog::trace("Log cleanup: Failed to delete log file: " . basename($filePath)); } } } DupLog::trace( sprintf( "Log cleanup: Completed. Deleted %d file(s), freed %s", $result['deleted_count'], size_format($result['freed_size']) ) ); return $result; } /** * Get the local overwrite params file name * * @param string $packageHash Package hash * * @return string */ public static function getOverwriteParamFileName(string $packageHash): string { return DUPLICATOR_LOCAL_OVERWRITE_PARAMS . '_' . $packageHash . '.json'; } /** * Write installer overwrite params file and trigger hook for legacy compatibility * * @param string $directory Directory where to write the file * @param string $packageHash Package hash for filename * @param array $params Parameters to write * * @return string Full path to the created file * * @throws Exception If file cannot be written */ public static function writeOverwriteParams(string $directory, string $packageHash, array $params): string { $filePath = trailingslashit($directory) . self::getOverwriteParamFileName($packageHash); if (file_put_contents($filePath, SnapJson::jsonEncodePPrint($params)) === false) { throw new Exception('Can\'t create overwrite param file: ' . $filePath); } /** * Fires after installer overwrite params file is created * * @param string $filePath Full path to the created file * @param array $params Parameters written to the file * @param string $packageHash Package hash used in filename */ do_action('duplicator_after_overwrite_params_created', $filePath, $params, $packageHash); return $filePath; } }
Fatal error: Uncaught Error: Class "Duplicator\Package\PackageUtils" not found in /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Package/DupPackage.php:19 Stack trace: #0 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Core/Models/HasTypeRegistration.php(39): Duplicator\Package\DupPackage::getType() #1 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Core/Bootstrap.php(513): Duplicator\Package\AbstractPackage::registerType() #2 /home/hexcom/public_html/digikids/wp-includes/class-wp-hook.php(353): Duplicator\Core\Bootstrap::registerCoreTypes() #3 /home/hexcom/public_html/digikids/wp-includes/class-wp-hook.php(377): WP_Hook->apply_filters() #4 /home/hexcom/public_html/digikids/wp-includes/plugin.php(523): WP_Hook->do_action() #5 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Core/Bootstrap.php(487): do_action() #6 /home/hexcom/public_html/digikids/wp-includes/class-wp-hook.php(353): Duplicator\Core\Bootstrap::addonsLoaded() #7 /home/hexcom/public_html/digikids/wp-includes/class-wp-hook.php(377): WP_Hook->apply_filters() #8 /home/hexcom/public_html/digikids/wp-includes/plugin.php(523): WP_Hook->do_action() #9 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Core/Addons/AddonsManager.php(120): do_action() #10 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Core/Bootstrap.php(95): Duplicator\Core\Addons\AddonsManager->initializeAddons() #11 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/duplicator-main.php(28): Duplicator\Core\Bootstrap::init() #12 /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/duplicator.php(48): require_once('/home/hexcom/pu...') #13 /home/hexcom/public_html/digikids/wp-settings.php(597): include_once('/home/hexcom/pu...') #14 /home/hexcom/public_html/digikids/wp-config.php(98): require_once('/home/hexcom/pu...') #15 /home/hexcom/public_html/digikids/wp-load.php(50): require_once('/home/hexcom/pu...') #16 /home/hexcom/public_html/digikids/wp-blog-header.php(13): require_once('/home/hexcom/pu...') #17 /home/hexcom/public_html/digikids/index.php(17): require('/home/hexcom/pu...') #18 {main} thrown in /home/hexcom/public_html/digikids/wp-content/plugins/duplicator/src/Package/DupPackage.php on line 19