/** * Tests the Revisr_Admin::clear_transients() method. */ function test_clear_transients() { //First set a transient and make sure it exists. Revisr_Admin::alert('test_error', true); $transient = get_transient('revisr_error'); $this->assertEquals('test_error', $transient); // Clear the transients and make sure they're really gone. Revisr_Admin::clear_transients(); $new_transient = get_transient('revisr_error'); $this->assertEquals(false, $new_transient); }
/** * Returns if the repo initialization was successful. * @access public */ public function success_init_repo() { Revisr_Admin::clear_transients(); $user = wp_get_current_user(); if (isset($this->options['username']) && $this->options['username'] != "") { $this->config_user_name($this->options['username']); } else { $this->config_user_name($user->user_login); } if (isset($this->options['email']) && $this->options['email'] != "") { $this->config_user_email($this->options['email']); } else { $this->config_user_email($user->user_email); } if (isset($this->options['remote_name']) && $this->options['remote_name'] != "") { $remote_name = $this->options['remote_name']; } else { $remote_name = 'origin'; } if (isset($this->options['remote_url']) && $this->options['remote_url'] != "") { $this->run("remote add {$remote_name} {$this->options['remote_url']}"); } $msg = sprintf(__('Successfully created a new repository.', 'revisr')); Revisr_Admin::log($msg, 'init'); wp_redirect(get_admin_url() . 'admin.php?page=revisr_settings&init=success'); exit; }
/** * Called if the repo initialization was successful. * Sets up the '.git/config' file for the first time. * @access public */ public function success_init_repo() { Revisr_Admin::clear_transients(); $user = wp_get_current_user(); // Set the default username to use in Git. if (isset($this->revisr->git->options['username']) && $this->revisr->git->options['username'] != '') { $this->revisr->git->set_config('user', 'name', $this->revisr->git->options['username']); } else { $this->revisr->git->set_config('user', 'name', $user->user_login); } // Set the default email to use in Git. if (isset($this->revisr->git->options['email']) && $this->revisr->git->options['email'] != '') { $this->revisr->git->set_config('user', 'email', $this->revisr->git->options['email']); } else { $this->revisr->git->set_config('user', 'email', $user->user_email); } // Set the default name of the remote. if (isset($this->revisr->git->options['remote_name']) && $this->revisr->git->options['remote_name'] != '') { $remote_name = $this->revisr->git->options['remote_name']; } else { $remote_name = 'origin'; } // Add the remote URL in Git if already set in the database. if (isset($this->revisr->git->options['remote_url']) && $this->revisr->git->options['remote_url'] != '') { $this->revisr->git->run('remote', array('add', $remote_name, $this->revisr->git->options['remote_url'])); } // Adds an .htaccess file to the "/.git" directory to prevent public access. if (is_writable($this->revisr->git->git_dir . '/.git/')) { file_put_contents($this->revisr->git->git_dir . '/.git/.htaccess', 'Deny from all' . PHP_EOL); } // Alerts the user. Revisr_Admin::log(__('Successfully created a new repository.', 'revisr'), 'init'); wp_redirect(get_admin_url() . 'admin.php?page=revisr_settings&init=success'); exit; }
/** * Called if the repo initialization was successful. * Sets up the '.git/config' file for the first time. * @access public */ public function success_init_repo($output, $args) { // Updates the repository properties. revisr()->git->is_repo = true; revisr()->git->git_dir = revisr()->git->get_git_dir(); revisr()->git->work_tree = revisr()->git->get_work_tree(); // Clear out any errors. Revisr_Admin::clear_transients(); // Grab the current user. $user = wp_get_current_user(); // Set the default username to use in Git. if (isset(revisr()->git->options['username']) && revisr()->git->options['username'] != '') { revisr()->git->set_config('user', 'name', revisr()->git->options['username']); } else { revisr()->git->set_config('user', 'name', $user->user_login); } // Set the default email to use in Git. if (isset(revisr()->git->options['email']) && revisr()->git->options['email'] != '') { revisr()->git->set_config('user', 'email', revisr()->git->options['email']); } else { revisr()->git->set_config('user', 'email', $user->user_email); } // Set the default name of the remote. if (isset(revisr()->git->options['remote_name']) && revisr()->git->options['remote_name'] != '') { $remote_name = revisr()->git->options['remote_name']; } else { $remote_name = 'origin'; } // Add the remote URL in Git if already set in the database. if (isset(revisr()->git->options['remote_url']) && revisr()->git->options['remote_url'] != '') { revisr()->git->run('remote', array('add', $remote_name, revisr()->git->options['remote_url'])); } // Adds an .htaccess file to the "/.git" directory to prevent public access. if (is_writable(revisr()->git->git_dir)) { file_put_contents(revisr()->git->git_dir . DIRECTORY_SEPARATOR . '.htaccess', 'Deny from all' . PHP_EOL); } // Fires after the repo has been created. do_action('revisr_post_init', $output); // Alerts the user. Revisr_Admin::log(__('Successfully created a new repository.', 'revisr'), 'init'); // Redirect if necessary (through skipped/legacy setup). if (!defined('REVISR_SETUP_INIT')) { Revisr_Admin::redirect(get_admin_url() . 'admin.php?page=revisr_settings&init=success'); } // Return true if we haven't exited already. return true; }
<?php } elseif ('check' === $action) { ?> <?php $dir = filter_input(INPUT_GET, 'revisr_manual_git_dir', FILTER_SANITIZE_STRING); revisr()->git->work_tree = $dir; if (!defined('REVISR_GIT_DIR')) { revisr()->git->git_dir = $dir . '/.git'; } if (revisr()->git->check_work_tree($dir)) { // Write it to the wp-config file if necessary. $line = "define('REVISR_WORK_TREE', '{$dir}');"; Revisr_Admin::replace_config_line('define *\\( *\'REVISR_WORK_TREE\'', $line); Revisr_Admin::clear_transients(); printf('<p>%s</p><br><a href="%s">%s</a>', __('Repository detected succesfully.', 'revisr'), get_admin_url() . 'admin.php?page=revisr', __('Continue to dashboard.', 'revisr')); } else { ?> <div class="alert"><p class="alert error"><?php _e('Repository not found. Double-check the path and try again.', 'revisr'); ?> </p></div> <input id="revisr-manual-repo-path" class="regular-text revisr-setup-input" name="revisr_manual_git_dir" value="<?php echo ABSPATH; ?> " /> <input type="hidden" name="action" value="check" /> <div class="revisr-setup-nav">