VersionPress\Git\MergeDriverInstaller::uninstallMergeDriver PHP Method

uninstallMergeDriver() public static method

Uninstalls a merge driver - removes 'vp-ini' sections from both .gitattributes and .git/config.
public static uninstallMergeDriver ( string $rootDir, string $pluginDir, string $vpdbDir )
$rootDir string
$pluginDir string
$vpdbDir string
    public static function uninstallMergeDriver($rootDir, $pluginDir, $vpdbDir)
    {
        $gitconfigPath = $rootDir . '/.git/config';
        $gitattributesPath = $rootDir . '/.gitattributes';
        $gitattributesContents = file_get_contents($pluginDir . '/src/Initialization/.gitattributes.tpl');
        $gitattributesVariables = ['vpdb-dir' => PathUtils::getRelativePath($rootDir, $vpdbDir)];
        $gitattributesContents = StringUtils::fillTemplateString($gitattributesVariables, $gitattributesContents);
        if (file_exists($gitattributesPath)) {
            $gitAttributes = file_get_contents($gitattributesPath);
            $gitAttributes = str_replace($gitattributesContents, '', $gitAttributes);
            if (trim($gitAttributes) === '') {
                unlink($gitattributesPath);
            } else {
                file_put_contents($gitattributesPath, $gitAttributes);
            }
        }
        if (file_exists($gitconfigPath)) {
            $gitConfig = file_get_contents($gitconfigPath);
            // https://regex101.com/r/eJ4rJ5/4
            $mergeDriverRegex = "/(\\[merge \\\"vp\\-ini\\\"\\]\\r?\\n)([^\\[]*)/";
            $gitConfig = preg_replace($mergeDriverRegex, '', $gitConfig, 1);
            file_put_contents($gitconfigPath, $gitConfig);
        }
    }

Usage Example

Esempio n. 1
0
/**
 * Most of the actual deactivation work is done here. Called either as a response
 * to the user confirming the deactivation on `?page=versionpress/admin/deactivate.php`
 * or is called directly from vp_deactivate() if the confirmation screen was not necessary.
 */
function vp_admin_post_confirm_deactivation()
{
    //nonce verification is performed according to 'deactivate-plugin_versionpress/versionpress.php'
    // as a standard deactivation token for which nonce is generated
    if (!defined('WP_CLI')) {
        vp_verify_nonce('deactivate-plugin_versionpress/versionpress.php');
        vp_check_permissions();
    }
    define('VP_DEACTIVATING', true);
    if (WpdbReplacer::isReplaced()) {
        WpdbReplacer::restoreOriginal();
    }
    if (file_exists(VERSIONPRESS_ACTIVATION_FILE)) {
        FileSystem::remove(VERSIONPRESS_ACTIVATION_FILE);
    }
    $filesChangedByDeactivation = [["type" => "path", "path" => VP_VPDB_DIR . "/*"], ["type" => "path", "path" => ABSPATH . WPINC . "/wp-db.php"], ["type" => "path", "path" => ABSPATH . WPINC . "/wp-db.php.original"], ["type" => "path", "path" => ABSPATH . "/.gitattributes"]];
    vp_force_action('versionpress', 'deactivate', null, [], $filesChangedByDeactivation);
    MergeDriverInstaller::uninstallMergeDriver(VP_PROJECT_ROOT, VERSIONPRESS_PLUGIN_DIR, VP_VPDB_DIR);
    deactivate_plugins("versionpress/versionpress.php", true);
    if (defined('WP_ADMIN')) {
        wp_safe_redirect(admin_url("plugins.php"));
        exit;
    }
}
All Usage Examples Of VersionPress\Git\MergeDriverInstaller::uninstallMergeDriver