/** * Serve the request to this endpoint. * * @param \ArrayAccess $get * @param \ArrayAccess $post * * @return Response * * @throws Exception|\Exception */ public function serve(\ArrayAccess $get, \ArrayAccess $post) { $now = \ITELIC\make_date_time(); $expires = $now->add(new \DateInterval("P1D")); $release = $this->activation->get_key()->get_product()->get_latest_release_for_activation($this->activation); // this really is a safeguard. if (!$release) { throw new \UnexpectedValueException(__("No releases available for this product.", Plugin::SLUG)); } if ($release->get_type() == Release::TYPE_SECURITY) { $notice = $release->get_meta('security-message', true); } else { if ($release->get_type() == Release::TYPE_MAJOR) { $notice = __("Warning! This is a major upgrade. Make sure you backup your website before updating.", Plugin::SLUG); } else { $notice = ''; } } /** * Filters the upgrade notice sent back from the API. * * @since 1.0 * * @param string $notice * @param Release $release */ $notice = apply_filters('itelic_get_release_upgrade_notice', $notice, $release); // if the installed version of the software is passed to the API, // and the installed version is greater than the version on record, create an update record // this accounts for manually updating the theme or plugin if (isset($get['installed_version'])) { $installed = itelic_get_release_by_version($this->key->get_product()->ID, $get['installed_version']); if ($installed && version_compare($installed->get_version(), $this->activation->get_release()->get_version(), '>')) { Update::create($this->activation, $installed); } } $info = array('version' => $release->get_version(), 'package' => \ITELIC\generate_download_link($this->activation), 'expires' => $expires->format(\DateTime::ISO8601), 'upgrade_notice' => $notice, 'type' => $release->get_type()); /** * Filter the version info returned by the API. * * @since 1.0 * * @param array $info * @param Key $key * @param Product $product */ $info = apply_filters('itelic_api_version_info', $info, $this->key, $this->key->get_product()); return new Response(array('success' => true, 'body' => array('list' => array($this->key->get_product()->ID => $info)))); }
/** * Get data to display for a single object. * * @param \ITELIC\Update $object * @param bool $raw * * @return array */ protected function get_fields_for_object(\ITELIC\Update $object, $raw = false) { return array('ID' => $object->get_pk(), 'activation' => $object->get_activation()->get_pk(), 'location' => $object->get_activation()->get_location(), 'release' => $raw ? $object->get_release()->get_pk() : $object->get_release()->get_version(), 'update_date' => $object->get_update_date()->format(DateTime::ISO8601), 'previous_version' => $object->get_previous_version()); }
/** * Create an update record. * * @api * * @since 1.0 * * @param array $args * * @return \ITELIC\Update|WP_Error */ function itelic_create_update($args) { $defaults = array('activation' => '', 'release' => '', 'update_date' => '', 'previous_version' => ''); $args = ITUtility::merge_defaults($args, $defaults); $activation = is_numeric($args['activation']) ? itelic_get_activation($args['activation']) : $args['activation']; if (!$activation) { return new WP_Error('invalid_activation', __("Invalid activation record.", \ITELIC\Plugin::SLUG)); } $release = is_numeric($args['release']) ? itelic_get_release($args['release']) : $args['release']; if (!$release) { return new WP_Error('invalid_release', __("Invalid release object.", \ITELIC\Plugin::SLUG)); } if (!empty($args['update_date'])) { $update_date = is_string($args['update_date']) ? \ITELIC\make_date_time($args['update_date']) : $args['update_date']; if (!$update_date instanceof DateTime) { return new WP_Error("invalid_update_date", __("Invalid update date.", \ITELIC\Plugin::SLUG)); } } else { $update_date = null; } return \ITELIC\Update::create($activation, $release, $update_date, $args['previous_version']); }