abstract class CommerceLicenseRemoteBase in Commerce License 7
Remote license base class.
Hierarchy
- class \Entity implements EntityInterface
- class \CommerceLicenseBase implements CommerceLicenseInterface, EntityBundlePluginValidableInterface
- class \CommerceLicenseRemoteBase implements CommerceLicenseSynchronizableInterface
- class \CommerceLicenseBase implements CommerceLicenseInterface, EntityBundlePluginValidableInterface
Expanded class hierarchy of CommerceLicenseRemoteBase
File
- includes/
plugins/ license_type/ base.inc, line 385 - Abstract and interface plugin implementation.
View source
abstract class CommerceLicenseRemoteBase extends CommerceLicenseBase implements CommerceLicenseSynchronizableInterface {
/**
* Constructor.
*
* @see Entity::__construct()
*/
public function __construct(array $values = array(), $entityType = NULL) {
parent::__construct($values, $entityType);
// Initialize the sync status.
// The [LANGUAGE_NONE][0]['value'] = 0; default is then added automatically.
if (!isset($this->sync_status)) {
$this->sync_status = array();
}
}
/**
* Implements EntityBundlePluginProvideFieldsInterface::fields().
*/
static function fields() {
$fields = parent::fields();
$fields['sync_status']['field'] = array(
'type' => 'list_integer',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
0 => t('N/A'),
COMMERCE_LICENSE_NEEDS_SYNC => t('Needs synchronization'),
COMMERCE_LICENSE_SYNCED => t('Synchronized'),
COMMERCE_LICENSE_SYNC_FAILED => t('Synchronization failed'),
),
),
);
$fields['sync_status']['instance'] = array(
'label' => t('Synchronization status'),
'required' => TRUE,
'widget' => array(
'type' => 'options_select',
),
);
return $fields;
}
/**
* Overrides CommerceLicenseBase::form().
*/
public function form(&$form, &$form_state) {
parent::form($form, $form_state);
// The sync status should not be editable by the customer.
$form['sync_status']['#access'] = FALSE;
}
/**
* Implements CommerceLicenseSynchronizableInterface::synchronize().
*/
public function synchronize() {
return TRUE;
}
/**
* Overrides CommerceLicenseBase::checkoutCompletionMessage().
*/
public function checkoutCompletionMessage() {
$message = '';
$sync_status = $this->wrapper->sync_status
->value();
switch ($sync_status) {
case COMMERCE_LICENSE_NEEDS_SYNC:
$message = t("Please wait while we're contacting the remote service...");
break;
case COMMERCE_LICENSE_SYNCED:
$message = 'Your license has been successfully created: <br />';
$message .= $this
->accessDetails();
break;
case COMMERCE_LICENSE_SYNC_FAILED_RETRY:
$message = t('Your license has been queued for processing.');
break;
case COMMERCE_LICENSE_SYNC_FAILED:
$message = t('Oops... We were unable to generate your credentials.');
break;
}
return $message;
}
/**
* Overrides CommerceLicenseBase::activate().
*/
public function activate($sync = TRUE) {
if ($sync) {
// The license will be activated after the initial synchronization.
$this->wrapper->status = COMMERCE_LICENSE_PENDING;
$this->wrapper->sync_status = COMMERCE_LICENSE_NEEDS_SYNC;
}
else {
$this->wrapper->status = COMMERCE_LICENSE_ACTIVE;
}
$this
->save();
}
/**
* Overrides CommerceLicenseBase::expire().
*/
public function expire($sync = TRUE) {
if ($sync) {
$this->wrapper->sync_status = COMMERCE_LICENSE_NEEDS_SYNC;
}
$this->wrapper->status = COMMERCE_LICENSE_EXPIRED;
$this
->save();
}
/**
* Overrides CommerceLicenseBase::suspend().
*/
public function suspend($sync = TRUE) {
if ($sync) {
$this->wrapper->sync_status = COMMERCE_LICENSE_NEEDS_SYNC;
}
$this->wrapper->status = COMMERCE_LICENSE_SUSPENDED;
$this
->save();
}
/**
* Overrides CommerceLicenseBase::revoke().
*/
public function revoke($sync = TRUE) {
if ($sync) {
$this->wrapper->sync_status = COMMERCE_LICENSE_NEEDS_SYNC;
}
$this->wrapper->status = COMMERCE_LICENSE_REVOKED;
$this
->save();
}
/**
* Overrides Entity::save().
*/
public function save() {
// If this is an update, get the original sync status for later comparison.
$original_sync_status = NULL;
if (!empty($this->license_id)) {
$this->original = entity_load_unchanged('commerce_license', $this->license_id);
$original_sync_status = $this->original->wrapper->sync_status
->value();
$sync_status = $this->wrapper->sync_status
->value();
$sync_status_changed = $original_sync_status != $sync_status;
$synced = $sync_status == COMMERCE_LICENSE_SYNCED;
$pending = $this->status == COMMERCE_LICENSE_PENDING;
// A pending license was just synchronized, update its status.
if ($pending && $sync_status_changed && $synced) {
$this->status = COMMERCE_LICENSE_ACTIVE;
}
}
// Perform the save. This allows a presave / insert / update hook to
// request synchronization by changing the sync_status field.
parent::save();
// Enqueue the sync if needed. Make sure not to enqueue if the license
// alredy needed sync before this update.
$sync_status = $this->wrapper->sync_status
->value();
$needs_sync = $sync_status == COMMERCE_LICENSE_NEEDS_SYNC;
$new_license = empty($this->license_id);
$sync_status_changed = $original_sync_status != $sync_status;
if ($needs_sync && ($new_license || $sync_status_changed)) {
commerce_license_enqueue_sync($this);
}
}
/**
* Overrides CommerceLicenseBase::isValid().
*/
public static function isValid() {
$valid = parent::isValid();
// Remote license types can't be used without the advancedqueue module.
return $valid && module_exists('advancedqueue');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceLicenseBase:: |
public | property | The date (unix timestamp) when the license expires. 0 for never. | |
CommerceLicenseBase:: |
public | property | Whether the module should expire the license automatically. | |
CommerceLicenseBase:: |
public | property | The date (unix timestamp) when the license was granted. | |
CommerceLicenseBase:: |
public | property | The license id. | |
CommerceLicenseBase:: |
public | property | The product_id of the licensed product. | |
CommerceLicenseBase:: |
public | property | The revision id. | |
CommerceLicenseBase:: |
public | property | The license status. | |
CommerceLicenseBase:: |
public | property | The license type (bundle). | |
CommerceLicenseBase:: |
public | property | The uid of the license owner. | |
CommerceLicenseBase:: |
public | property |
License metadata wrapper. Overrides Entity:: |
|
CommerceLicenseBase:: |
public | function |
Implements CommerceLicenseInterface::accessDetails(). Overrides CommerceLicenseInterface:: |
2 |
CommerceLicenseBase:: |
public | function |
Implements CommerceLicenseInterface::formSubmit(). Overrides CommerceLicenseInterface:: |
|
CommerceLicenseBase:: |
public | function |
Implements CommerceLicenseInterface::formValidate(). Overrides CommerceLicenseInterface:: |
1 |
CommerceLicenseBase:: |
public | function |
Implements CommerceLicenseInterface::isConfigurable(). Overrides CommerceLicenseInterface:: |
3 |
CommerceLicenseBase:: |
public | function |
Implements CommerceLicenseInterface::renew(). Overrides CommerceLicenseInterface:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::activate(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::checkoutCompletionMessage(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::expire(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
static | function |
Implements EntityBundlePluginProvideFieldsInterface::fields(). Overrides CommerceLicenseBase:: |
1 |
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::form(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public static | function |
Overrides CommerceLicenseBase::isValid(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::revoke(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides Entity::save(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Overrides CommerceLicenseBase::suspend(). Overrides CommerceLicenseBase:: |
|
CommerceLicenseRemoteBase:: |
public | function |
Implements CommerceLicenseSynchronizableInterface::synchronize(). Overrides CommerceLicenseSynchronizableInterface:: |
1 |
CommerceLicenseRemoteBase:: |
public | function |
Constructor. Overrides CommerceLicenseBase:: |
|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. |