/** * * * @since 1.4 */ private function upgrade() { $current_version = $this->db->getOption('version'); if ($current_version === self::VERSION) { return 2; } // The 'is_first_activation' flag is set in the callback of 'register_activation_hook()' // to be sure that the redirect at the end of this method fires when the plugin options have // not been initialised but only after the first ever activation. // It's quite uself during testing, when the options array is manually deleted from the database // while the plugin is running. $is_first_activation = $this->db->getOption('is_first_activation'); // Is it the first ever launch? Has the options array been corrupted? if ((int) $current_version === 0) { $this->db->setOptions(array('instal_date' => time())); } elseif (version_compare($current_version, self::MIN_VERSION, '<')) { $this->registerFatalError(sprintf(__('The version you are upgrading from is unsupported. In order to keep your settings, please, ' . 'update to an older version first, then try again to upgrade to %s. %sMore information in the %sFAQs%s.', 'sitetree'), 'SiteTree ' . self::VERSION, '<em>', '<a href="' . self::website('faqs') . '" target="_blank">', '</a></em>')); return false; } else { include $this->dirPath . '/core/sitetree-upgrader.class.php'; $options = $this->db->getOptions(); $defaults = $this->dataController()->defaults(); $upgrader = new SiteTreeUpgrader($options, $defaults); $this->db->setOptions($upgrader->upgrade()); } $this->db->setOption('version', self::VERSION); $this->db->setOption('last_updated', current_time('timestamp')); if ($is_first_activation) { $this->db->deleteOption('is_first_activation'); SiteTreeUtilities::adminRedirect($this->dataController()->page('dashboard', false)->id); } return true; }
/** * * * @since 1.4 */ public function processAction($action, $page_id, &$input = array(), $tab_id = null) { switch ($action) { case 'update': $message = $url = ''; $dataController = $this->plugin->dataController(); $data = $dataController->sanitiseData($input, $page_id, $tab_id); if ($dataController->isGoogleRelatedPage($page_id)) { $message = __('Settings saved. %sView Sitemap%s', 'sitetree'); $url = $this->plugin->googleSitemapPermalink(); if ($this->db->setOptions($data, true)) { $this->db->invalidateCache('xml'); if (!$this->db->getOption('ping', true)) { $this->plugin->pingController()->unschedulePing(); } } } else { $message = __('Settings saved. %sView Archive%s', 'sitetree'); $url = esc_url(get_permalink($this->db->getOption('page_for_sitemap'))); if ($this->db->setOptions($data, true)) { $this->db->invalidateCache('html5'); } } $this->registerErrorMessage(sprintf($message, '<a href="' . $url . '" target="sitetree_admin">', '</a>')); SiteTreeUtilities::adminRedirect($page_id, array('tab' => $tab_id, 'settings-updated' => 'true')); case 'rebuild_google': $now = time(); if ($now - $this->db->getOption('date', $now, 'stats_xml') < 11) { $this->registerErrorMessage(__('No need to rebuild the Sitemap every 10 seconds. Take a break!', 'sitetree')); SiteTreeUtilities::adminRedirect($page_id, array('rebuilt' => 'false')); } $this->plugin->rebuildGoogleSitemap(); SiteTreeUtilities::adminRedirect($page_id); case 'rebuild_html5': $now = time(); if ($now - $this->db->getOption('date', $now, 'stats_html5') < 11) { $this->registerErrorMessage(__('No need to rebuild the Archive every 10 seconds. Take a break!', 'sitetree')); SiteTreeUtilities::adminRedirect($page_id, array('rebuilt' => 'false')); } $this->plugin->rebuildHtml5Sitemap(); SiteTreeUtilities::adminRedirect($page_id); case 'cancel_ping': $this->plugin->pingController()->unschedulePing(); SiteTreeUtilities::adminRedirect($page_id); case 'update_config': // If this is the first activation, load defaults in db if ($this->db->getOption('page_for_sitemap', null) === null) { $defaults = $this->plugin->dataController()->html5Defaults(); $this->db->setOptions($defaults, true); $this->plugin->rebuildHtml5Sitemap(); } $data = $this->plugin->dataController()->sanitiseData($input, $page_id); $this->db->setOptions($data, true); SiteTreeUtilities::adminRedirect($page_id); case 'enable': // If this is the first activation, load defaults in db if ($this->db->getOption('enable_xml', null) === null) { $defaults = $this->plugin->dataController()->googleDefaults(); $this->db->setOptions($defaults, true); $this->plugin->rebuildGoogleSitemap(); } $this->db->setOption('enable_xml', true); SiteTreeUtilities::adminRedirect($page_id); case 'disable': $this->db->setOption('enable_xml', false); $this->plugin->cleanUp(); SiteTreeUtilities::adminRedirect($page_id); case 'dismiss': $this->db->setOption('msg_displayed', true); SiteTreeUtilities::adminRedirect($page_id); } }