HM\BackUpWordPress\Path::move_old_backups PHP Method

move_old_backups() public method

Move backup files from an existing directory and the new location.
public move_old_backups ( string $from )
$from string The path to move the backups from.
    public function move_old_backups($from)
    {
        if (!is_readable($from)) {
            return;
        }
        if (!wp_is_writable(Path::get_path())) {
            return;
        }
        // Move any existing backups
        if ($handle = opendir($from)) {
            // Loop through the backup directory
            while (false !== ($file = readdir($handle))) {
                // Find all zips
                if ('zip' === pathinfo($file, PATHINFO_EXTENSION)) {
                    // Try to move them
                    if (!@rename(trailingslashit($from) . $file, trailingslashit(Path::get_path()) . $file)) {
                        // If we can't move them then try to copy them
                        copy(trailingslashit($from) . $file, trailingslashit(Path::get_path()) . $file);
                    }
                }
            }
            closedir($handle);
        }
        // Delete the old directory if it's inside WP_CONTENT_DIR
        if (false !== strpos($from, WP_CONTENT_DIR) && Path::get_path() !== $from) {
            rmdirtree($from);
        }
    }