public static function check(EasyRecipeSettings $settings) { $log = EasyRecipeLogger::getLog('update'); /** * If the settings haven't been updated to show that we've created taxonomies, schedule the taxonomy creation. * Do this in the background because it may take quite some time especially on underpowered shared servers (10+ secs on our dedicated test server for our moderately sized test blog) */ if (!$settings->taxonomiesCreated) { $scheduler = new EasyRecipeScheduler(EasyRecipeTaxonomies::UPDATE_TAXONOMIES); /** * If we are running in CRON, set up the hook to catch the update event when it fires * Otherwise, get the scheduler to schedule the update via cron right now * Both of these situations might occur multiple times before the taxonomy creation is complete. The scheduler will handle that */ if (defined('DOING_CRON')) { /** * If the job isn't already running, set it so but allow it to timeout after 10 mins so that if it fails, it won't be flagged as running forever * Then setup the hook to actually do the work */ if (!$scheduler->isRunning()) { self::$taxonomies = new EasyRecipeTaxonomies($scheduler); add_action(EasyRecipeTaxonomies::UPDATE_TAXONOMIES, array(self::$taxonomies, 'updateAll')); } } else { $scheduler->runNow(); } } }
/** * @static * @return EasyRecipeSettings */ static function getInstance() { $freeSettings = null; $updateOptions = false; /** * If we haven't already instantiated settings, try to do it from the options */ if (!self::$instance) { self::$instance = get_option('EasyRecipe', false); if (!self::$instance) { self::$instance = new EasyRecipeSettings(); /** * If we're updating from a very early version, copy the old settings which are still relevant * Any not set in the defaults are deprecated and we can drop them */ $v31Settings = get_option('ERSettings'); if (!empty($v31Settings)) { foreach ($v31Settings as $setting => $value) { if (isset(self::$defaultSettings[$setting])) { self::$instance->{$setting} = $value; } } $updateOptions = true; } } /** * Fixup possible legacy problems where the options weren't stored as the correct class */ if (!self::$instance instanceof EasyRecipeSettings) { self::$instance = new EasyRecipeSettings(self::$instance); $updateOptions = true; } /** * If this is the first run of the plugin after an update, see if we need to do any processing specific to this update. * Also do the update check if the taxonomies haven't been created yet * * TODO - determine if this is a new install - won't need to check if so? */ $updateCheck = version_compare(self::$instance->settingsVersion, EasyRecipe::$pluginVersion) == -1 || !self::$instance->taxonomiesCreated; if ($updateCheck) { EasyRecipeUpdate::check(self::$instance); /** * Save the new settings version (will be the same as the installed pluginVersion) */ self::$instance->settingsVersion = EasyRecipe::$pluginVersion; $updateOptions = true; } /** * Set any defaults which haven't been set in the current version (i.e. new settings just introduced) * TODO - remove any options no longer needed? */ foreach (self::$defaultSettings as $setting => $default) { if (!isset(self::$instance->{$setting})) { self::$instance->{$setting} = $default; $updateOptions = true; } } /** * Update the settings if we changed them during construction */ if ($updateOptions) { update_option('EasyRecipe', self::$instance); } } return self::$instance; }