/**
 * Get an activation record by its location.
 *
 * @api
 *
 * @since 1.0
 *
 * @param string      $location
 * @param \ITELIC\Key $key
 *
 * @return \ITELIC\Activation|null
 */
function itelic_get_activation_by_location($location, \ITELIC\Key $key)
{
    $activations = itelic_get_activations(array('location' => $key->is_online_product() ? itelic_normalize_url($location) : $location, 'key' => $key->get_key(), 'items_per_page' => 1));
    if (empty($activations)) {
        return null;
    }
    return reset($activations);
}
Пример #2
0
 /**
  * Delete the license key.
  */
 public function delete()
 {
     /**
      * Fires before a key is deleted.
      *
      * @since 1.0
      *
      * @param Activation $this
      */
     do_action('itelic_delete_key', $this);
     $activations = itelic_get_activations(array('key' => $this->get_key()));
     foreach ($activations as $activation) {
         $activation->delete();
     }
     $renewals = itelic_get_renewals(array('key' => $this->get_key()));
     foreach ($renewals as $renewal) {
         $renewal->delete();
     }
     parent::delete();
     /**
      * Fires after a key is deleted.
      *
      * @since 1.0
      *
      * @param Activation $this
      */
     do_action('itelic_deleted_key', $this);
 }
Пример #3
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();
 }
 /**
  * Get a list of activations for a certain key.
  *
  * ## Options
  *
  * <key>
  * : Get activations for this license key.
  *
  * [--<field>=<value>]
  * : Additional parameters passed to the activations query.
  *
  * [--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)
 {
     list($key) = $args;
     $key = itelic_get_key($key);
     if (!$key) {
         WP_CLI::error("Invalid key.");
     }
     $query_args = wp_parse_args($assoc_args, array('items_per_page' => 20, 'page' => 1, 'key' => $key->get_key()));
     $query_args['order'] = array('activation' => 'DESC');
     $results = itelic_get_activations($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', 'location', 'status', 'version');
     }
     $formatter = $this->get_formatter($assoc_args);
     $formatter->display_items($items);
 }