uninstallationShouldRemoveGitRepo() public static method

Returns true if VP uninstallation should remove the Git repo from the root folder (and back it up somewhere). This is true if the first commit is VersionPress commit. Otherwise, the Git repo was probably created by the user before VP was installed and we should keep the repo untouched.
Esempio n. 1
0
    // Flushing rewrite rules after clone / pull / push
    //----------------------------------
    add_action('wp_loaded', function () {
        if (get_transient('vp_flush_rewrite_rules') && !defined('WP_CLI')) {
            require_once ABSPATH . 'wp-admin/includes/misc.php';
            require_once ABSPATH . 'wp-admin/includes/file.php';
            flush_rewrite_rules();
            delete_transient('vp_flush_rewrite_rules');
        }
    });
}
//----------------------------------
// Auto-update
//----------------------------------
add_filter('automatic_updates_is_vcs_checkout', function () {
    $forceUpdate = UninstallationUtil::uninstallationShouldRemoveGitRepo();
    // first commit was created by VersionPress
    return !$forceUpdate;
    // 'false' forces the update
});
function vp_register_hooks()
{
    global $versionPressContainer;
    /** @var Committer $committer */
    $committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER);
    /** @var Mirror $mirror */
    $mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR);
    /** @var DbSchemaInfo $dbSchemaInfo */
    $dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA);
    /** @var VpidRepository $vpidRepository */
    $vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY);
Esempio n. 2
0
<?php

/**
 * Uninstallation script for VersionPress. Most things already happened in the
 * `vp_admin_post_confirm_deactivation` hook; here, we just move the .git repo.
 *
 * Testing tip: place exit() at the end of the script and then in the browser
 * just go back and try again.
 *
 * @see vp_admin_post_confirm_deactivation()
 */
use VersionPress\Utils\FileSystem;
use VersionPress\Utils\SecurityUtils;
use VersionPress\Utils\UninstallationUtil;
defined('WP_UNINSTALL_PLUGIN') or die('Direct access not allowed');
require_once dirname(__FILE__) . '/bootstrap.php';
if (UninstallationUtil::uninstallationShouldRemoveGitRepo()) {
    $backupsDir = WP_CONTENT_DIR . '/vpbackups';
    if (!file_exists($backupsDir)) {
        FileSystem::mkdir($backupsDir);
        file_put_contents($backupsDir . '/.gitignore', 'git-backup-*');
        SecurityUtils::protectDirectory($backupsDir);
    }
    $backupPath = $backupsDir . '/git-backup-' . date("YmdHis");
    FileSystem::rename(ABSPATH . '.git', $backupPath, true);
    $productionGitignore = ABSPATH . '.gitignore';
    $templateGitignore = __DIR__ . '/src/Initialization/.gitignore.tpl';
    if (FileSystem::filesHaveSameContents($productionGitignore, $templateGitignore)) {
        FileSystem::remove($productionGitignore);
    }
}