/** * Run a database upgrade routine on admin init * * Happens immediately on admin init so data can be upgraded before any * other actions take place. */ public static function database_upgrade() { // Get the DB version $raw_db_version = self::get_raw_db_version(); $needs_update = false; // Upgrade from before 1.0.0 - consolidate options into 1 array if (empty($raw_db_version)) { // upgrade old beta non-serialized settings if applicable @todo test this if (get_option('pushup-username') || get_option('pushup-website-push-id') || get_option('pushup-api-key')) { // move into the new serialized option update_option(self::$option_key, array('username' => get_option('pushup-username', ''), 'api-key' => get_option('pushup-api-key', ''), 'website-push-id' => get_option('pushup-website-push-id', ''), 'user-id' => PushUp_Notifications_JSON_API::get_user_id(), 'post-title' => __('Just published...', 'pushup'), 'db-version' => self::$database_version)); // delete old options delete_option('pushup-username'); delete_option('pushup-website-push-id'); delete_option('pushup-api-key'); // Option needs updating $needs_update = true; } } // Get any existing settings $settings = get_option(self::$option_key); // Override the 'db-version' to current if (isset($settings['db-version']) && $settings['db-version'] !== self::$database_version) { $needs_update = true; } // Maybe add 'post-title' to settings if ($raw_db_version < 1030 && empty($settings['post-title'])) { $settings['post-title'] = __('Just published...', 'pushup'); $needs_update = true; } // Maybe add 'user-id' to settings if ($raw_db_version < 1040 && empty($settings['user-id'])) { $settings['user-id'] = PushUp_Notifications_JSON_API::get_user_id(); $needs_update = true; } // Update the option if it needs it if (true === $needs_update) { // Always update to the current database version. If this doesn't // happen, exil and mysterious bugs appear out of no-where. $settings['db-version'] = self::$database_version; // Update the option update_option(self::$option_key, $settings); } }