public function test_exception_thrown_if_duplicate_location()
 {
     $key = $this->key_factory->create_and_get(array('customer' => 1, 'product' => $this->product_factory->create()));
     $this->activation_factory->create(array('location' => 'test_exception_thrown_if_duplicate_location.com', 'key' => $key));
     $this->setExpectedException('\\InvalidArgumentException');
     Activation::create($key, 'test_exception_thrown_if_duplicate_location.com');
 }
Esempio n. 2
0
 /**
  * Create activation records for a license key.
  *
  * @param \ITELIC\Key $key
  */
 protected function create_activations_for_key(ITELIC\Key $key)
 {
     if (in_array($key->get_status(), array(\ITELIC\Key::EXPIRED, \ITELIC\Key::DISABLED))) {
         return;
     }
     $limit = $key->get_max();
     if (empty($limit)) {
         $limit = 20;
     }
     $limit = min($limit, $limit / 2 + 2);
     $created = $key->get_transaction()->post_date_gmt;
     $end = \ITELIC\make_date_time($created);
     $end->add(new DateInterval('P5D'));
     $creation_date = $this->faker->dateTimeBetween($created, $end);
     $release = $this->get_release_for_date($key, $creation_date);
     if (!$release) {
         WP_CLI::error("Release not created.");
     }
     \ITELIC\Activation::create($key, $this->faker->domainName, $creation_date, $release);
     $count = rand(0, $limit - 1);
     if (!$count) {
         return;
     }
     $now = new DateTime();
     for ($i = 0; $i < $count; $i++) {
         $expires = $key->get_expires();
         if ($expires > $now) {
             $max = $now;
         } else {
             $max = $expires;
         }
         $creation_date = $this->faker->dateTimeBetween($created, $max);
         $release = $this->get_release_for_date($key, $creation_date);
         try {
             $a = \ITELIC\Activation::create($key, $this->faker->domainName, $creation_date, $release);
         } catch (LogicException $e) {
             continue;
         } catch (IronBound\DB\Exception $e) {
             continue;
         }
         if (!rand(0, 3)) {
             $deactivate_date = $this->faker->dateTimeBetween($creation_date, $max);
             $a->deactivate($deactivate_date);
         }
     }
 }
/**
 * Create an activation record.
 *
 * @api
 *
 * @since 1.0
 *
 * @param array $args
 *
 * @return \ITELIC\Activation|WP_Error
 */
function itelic_create_activation($args)
{
    $defaults = array('key' => '', 'location' => '', 'activation' => '', 'release' => '', 'status' => '', 'track' => 'stable');
    $args = ITUtility::merge_defaults($args, $defaults);
    $key = is_string($args['key']) ? itelic_get_key($args['key']) : $args['key'];
    if (!$key) {
        return new WP_Error('invalid_key', __("Invalid Key", \ITELIC\Plugin::SLUG));
    }
    $location = $args['location'];
    if (!empty($args['activation'])) {
        if (is_string($args['activation'])) {
            $activation = \ITELIC\make_date_time($args['activation']);
        } else {
            $activation = $args['activation'];
        }
        if (!$activation instanceof DateTime) {
            return new WP_Error('invalid_activation', __("Invalid activation date.", \ITELIC\Plugin::SLUG));
        }
    } else {
        $activation = null;
    }
    if (!empty($args['release'])) {
        if (is_string($args['release'])) {
            $release = itelic_get_release($args['release']);
        } else {
            $release = $args['release'];
        }
        if (!$release instanceof \ITELIC\Release) {
            return new WP_Error('invalid_release', __("Invalid release.", \ITELIC\Plugin::SLUG));
        }
    } else {
        $release = null;
    }
    $status = $args['status'];
    try {
        $activation = \ITELIC\Activation::create($key, $location, $activation, $release, $status);
        $activation->add_meta('track', $args['track']);
    } catch (Exception $e) {
        return new WP_Error('exception', $e->getMessage());
    }
    return $activation;
}