예제 #1
0
/**
 * Get a release by its version number.
 *
 * @api
 *
 * @since 1.0
 *
 * @param int    $product_id
 * @param string $version
 *
 * @return \ITELIC\Release
 */
function itelic_get_release_by_version($product_id, $version)
{
    $query = itelic_get_releases(array('product' => absint($product_id), 'version' => $version, 'items_per_page' => 1));
    foreach ($query as $release) {
        return $release;
    }
    return null;
}
예제 #2
0
 /**
  * Pause this release.
  *
  * @since 1.0
  */
 public function pause()
 {
     if ($this->status != self::STATUS_PAUSED) {
         $this->status = self::STATUS_PAUSED;
         $this->update('status', self::STATUS_PAUSED);
     }
     if ($this->get_type() != self::TYPE_PRERELEASE) {
         $releases = itelic_get_releases(array('items_per_page' => 1, 'page' => 1, 'product' => $this->get_product()->ID, 'type' => array(self::TYPE_MAJOR, self::TYPE_MINOR, self::TYPE_SECURITY), 'status' => array(self::STATUS_ACTIVE, self::STATUS_ARCHIVED), 'order' => array('start_date' => 'DESC')));
         $prev_release = reset($releases);
         if ($prev_release) {
             $download_id = $this->get_product()->get_feature('licensing', array('field' => 'update-file'));
             $download_data = get_post_meta($download_id, '_it-exchange-download-info', true);
             $download_data['source'] = wp_get_attachment_url($prev_release->get_download()->ID);
             update_post_meta($download_id, '_it-exchange-download-info', $download_data);
             $this->get_product()->update_feature('licensing', array('version' => $prev_release->get_version()));
         }
     }
     if (!isset($prev_release) || !$prev_release instanceof Release) {
         $prev_release = null;
     }
     wp_cache_delete($this->get_product()->ID, 'itelic-changelog');
     /**
      * Fires when a release is paused.
      *
      * @since 1.0
      *
      * @param Release $this
      * @param Release $prev_release Release that we are reverting to.
      */
     do_action('itelic_pause_release', $this, $prev_release);
 }
예제 #3
0
 /**
  * Get the latest release available at a certain date.
  *
  * @param \ITELIC\Key $key
  * @param DateTime    $date GMT.
  * @param string      $track
  *
  * @return \ITELIC\Release
  */
 protected function get_release_for_date(ITELIC\Key $key, DateTime $date, $track = 'stable')
 {
     $types = array(\ITELIC\Release::TYPE_MAJOR, \ITELIC\Release::TYPE_MINOR, \ITELIC\Release::TYPE_SECURITY);
     if ($track == 'pre-release') {
         $types[] = \ITELIC\Release::TYPE_PRERELEASE;
     }
     $releases = itelic_get_releases(array('product' => $key->get_product()->ID, 'order' => array('start_date' => 'DESC'), 'start_date' => array('before' => $date->format('Y-m-d H:i:s')), 'items_per_page' => 1, 'sql_calc_found_rows' => false, 'type' => $types));
     return reset($releases);
 }
예제 #4
0
/**
 * Delete license keys when the product is deleted.
 *
 * @since 1.0
 *
 * @param int $post_id
 */
function delete_keys_and_releases_when_product_is_deleted($post_id)
{
    if (get_post_type($post_id) != 'it_exchange_prod') {
        return;
    }
    $keys = itelic_get_keys(array('product' => $post_id));
    foreach ($keys as $key) {
        $key->delete();
    }
    $releases = itelic_get_releases(array('product' => $post_id));
    foreach ($releases as $release) {
        $release->delete();
    }
}
예제 #5
0
 /**
  * Generate update records.
  *
  * ## Options
  *
  * <product>
  * : Product ID to generate update records for.
  *
  * @param $args
  * @param $assoc_args
  */
 public function generate($args, $assoc_args)
 {
     list($product) = $args;
     $product = itelic_get_product($product);
     if (!$product) {
         WP_CLI::error("Invalid product ID");
     }
     $releases = itelic_get_releases(array('product' => $product->ID, 'order' => array('start_date' => 'ASC')));
     $notify = \WP_CLI\Utils\make_progress_bar(sprintf("Generating Updates: %d", $product->ID), count($releases));
     foreach ($releases as $release) {
         switch ($release->get_type()) {
             case \ITELIC\Release::TYPE_MAJOR:
                 $percent_updated = 75;
                 break;
             case \ITELIC\Release::TYPE_MINOR:
                 $percent_updated = 90;
                 break;
             case \ITELIC\Release::TYPE_SECURITY:
                 $percent_updated = 95;
                 break;
             case \ITELIC\Release::TYPE_PRERELEASE:
                 $percent_updated = 95;
                 break;
             default:
                 throw new InvalidArgumentException("Invalid release type.");
         }
         $total_activations = new \ITELIC\Query\Activations(array('activation' => array('before' => $release->get_start_date()->format('Y-m-d H:i:s')), 'product' => $product->ID, 'return_value' => 'count'));
         $total_activations = $total_activations->get_results();
         $activations = itelic_get_activations(array('activation' => array('before' => $release->get_start_date()->format('Y-m-d H:i:s')), 'product' => $product->ID, 'order' => 'rand', 'items_per_page' => $total_activations * ($percent_updated / 100)));
         foreach ($activations as $activation) {
             if ($activation->get_deactivation() && $activation->get_deactivation() > $release->get_start_date()) {
                 continue;
             }
             if ($release->get_type() == ITELIC\Release::TYPE_MAJOR) {
                 $days = rand(0, 10);
             } else {
                 $days = rand(0, 4);
             }
             $upgade_date = $release->get_start_date()->add(new DateInterval("P{$days}D"));
             \ITELIC\Update::create($activation, $release, $upgade_date);
         }
         if ($release->get_status() == \ITELIC\Release::STATUS_ARCHIVED) {
             $release->set_status(\ITELIC\Release::STATUS_ACTIVE);
             $release->archive();
         }
         $notify->tick();
     }
     $notify->finish();
 }
예제 #6
0
 /**
  * Get a list of releases.
  *
  * ## Options
  *
  * [--<field>=<value>]
  * : Additional parameters passed to the releases query.
  *
  * [--show-changes]
  * : Include the changelog.
  *
  * [--fields=<fields>]
  * : Limit the output to specific object fields.
  *
  * [--format=<format>]
  * : Accepted values: table, json, csv. Default: table
  *
  * [--raw]
  * : Return raw values. IDs instead of human readable names.
  *
  * @param $args
  * @param $assoc_args
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     $query_args = wp_parse_args($assoc_args, array('items_per_page' => 20, 'page' => 1));
     $query_args['order'] = array('ID' => 'DESC');
     $results = itelic_get_releases($query_args);
     $items = array();
     foreach ($results as $item) {
         $items[] = $this->get_fields_for_object($item, \WP_CLI\Utils\get_flag_value($assoc_args, 'raw', false));
     }
     if (empty($assoc_args['fields'])) {
         $assoc_args['fields'] = array('ID', 'product', 'version', 'type', 'status', 'download', 'started');
         if (!empty($assoc_args['show-changes'])) {
             $assoc_args['fields'][] = 'changelog';
         }
     }
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($items);
 }
예제 #7
0
 /**
  * Get the latest release available for an activation record.
  *
  * By default, returns the latest version saved. But is used for getting
  * pre-release or restricted versions.
  *
  * @since 1.0
  *
  * @param Activation $activation
  *
  * @return Release
  */
 public function get_latest_release_for_activation(Activation $activation)
 {
     $track = $activation->get_meta('track', true);
     if (!$track || $track != 'pre-release') {
         $version = it_exchange_get_product_feature($this->ID, 'licensing', array('field' => 'version'));
         $release = itelic_get_release_by_version($this->ID, $version);
     } else {
         $releases = itelic_get_releases(array('product' => $activation->get_key()->get_product()->ID, 'order' => array('start_date' => 'DESC'), 'items_per_page' => 1));
         $release = reset($releases);
     }
     /**
      * Filter the latest release for an activation record.
      *
      * @since 1.0
      *
      * @param Release    $release
      * @param Activation $activation
      */
     return apply_filters('itelic_get_latest_release_for_activation', $release, $activation);
 }