commerce_square.install in Commerce Square Connect 7
Same filename and directory in other branches
Commerce Square install file.
File
commerce_square.installView source
<?php
/**
* @file
* Commerce Square install file.
*/
/**
* Implements hook_requirements().
*/
function commerce_square_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$library = libraries_detect('square');
if ($library['installed'] === TRUE) {
$requirements['commerce_square'] = array(
'title' => $t('Square Connect SDK'),
'value' => $t('Installed: @version', array(
'@version' => $library['version'],
)),
'severity' => REQUIREMENT_OK,
);
// Compare installed version.
list($major, $minor, $patch) = explode('.', $library['version']);
if ($major != 2) {
$requirements['commerce_square']['severity'] = REQUIREMENT_ERROR;
$requirements['commerce_square']['description'] = $t('The Square Connect SDK v2.x.x is only supported. Currently @version is discovered', array(
'@version' => $library['version'],
));
}
}
else {
$requirements['commerce_square'] = array(
'title' => $t('Square Connect SDK'),
'value' => $t('Missing'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Square Connect SDK library missing. Download the library from <a href="!url">!url</a> and place it in to sites/all/libraries/square', array(
'!url' => $library['download url'],
)),
);
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function commerce_square_uninstall() {
variable_del('commerce_square_settings');
}
/**
* Migrate configuration to new format.
*/
function commerce_square_update_7001() {
$conditions = array(
'event' => 'commerce_payment_methods',
'plugin' => 'reaction rule',
'active' => TRUE,
'owner' => 'rules',
);
$rules = entity_load('rules_config', FALSE, $conditions);
/** @var RulesReactionRule $rule */
foreach ($rules as $rule) {
foreach ($rule as $child) {
if ($child instanceof RulesAction) {
if (!empty($child->settings) && !empty($child->settings['payment_method'])) {
$payment_method = $child->settings['payment_method'];
// Payment methods without settings are a string with method ID.
if (!is_array($payment_method) || empty($payment_method['settings'])) {
continue;
}
if ($payment_method['method_id'] == 'commerce_square') {
$payment_method_settings = $payment_method['settings'];
$square_settings = array(
'app_name' => $payment_method_settings['app_name'],
'app_secret' => $payment_method_settings['app_secret'],
'test_app_id' => $payment_method_settings['test_app_id'],
'test_access_token' => $payment_method_settings['test_access_token'],
'live_app_id' => $payment_method_settings['live_app_id'],
'live_access_token' => $payment_method_settings['live_access_token'],
'live_access_token_expiry' => $payment_method_settings['live_access_token_expiry'],
);
variable_set('commerce_square_settings', $square_settings);
foreach (array_keys($square_settings) as $key_to_remove) {
unset($payment_method_settings[$key_to_remove]);
}
unset($payment_method_settings['test']);
unset($payment_method_settings['live']);
$child->settings['payment_method']['settings'] = $payment_method_settings;
$child
->save();
}
}
}
}
}
}
/**
* Ensure IntegrationChargeRequest is in class registry.
*/
function commerce_square_update_7002() {
registry_rebuild();
}
/**
* Ensure changes to commerce_square.form.js exist in JS aggregates.
*/
function commerce_square_update_7003() {
drupal_flush_all_caches();
}
Functions
Name | Description |
---|---|
commerce_square_requirements | Implements hook_requirements(). |
commerce_square_uninstall | Implements hook_uninstall(). |
commerce_square_update_7001 | Migrate configuration to new format. |
commerce_square_update_7002 | Ensure IntegrationChargeRequest is in class registry. |
commerce_square_update_7003 | Ensure changes to commerce_square.form.js exist in JS aggregates. |