Commit b9644f9d authored by Rich's avatar Rich
Browse files

wip

parent 53550e19
<?php
use CRM_Actionlinks_ExtensionUtil as E;
class CRM_Actionlinks_BAO_ActionLink extends CRM_Actionlinks_DAO_ActionLink {
/**
* Create a new ActionLink based on array-data
*
* @param array $params key-value pairs
* @return CRM_Actionlinks_DAO_ActionLink|NULL
*
public static function create($params) {
$className = 'CRM_Actionlinks_DAO_ActionLink';
$entityName = 'ActionLink';
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
$instance = new $className();
$instance->copyValues($params);
$instance->save();
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
return $instance;
} */
}
<?php
/**
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
* Generated from /buildkit/build/dmaster/sites/default/files/civicrm/ext/actionlinks/xml/schema/CRM/Actionlinks/ActionLink.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:3954e8566f98ee0ff680eebfef7fb50f)
*/
/**
* Database access object for the ActionLink entity.
*/
class CRM_Actionlinks_DAO_ActionLink extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
public static $_tableName = 'civicrm_action_link';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var bool
*/
public static $_log = FALSE;
/**
* Unique ActionLink ID
*
* @var int
*/
public $id;
/**
* Administrative name
*
* @var string
*/
public $name;
/**
* Description
*
* @var text
*/
public $description;
/**
* Whether this link is active.
*
* @var bool
*/
public $is_active;
/**
* The URL you would normally redirect to
*
* @var string
*/
public $allowed_url;
/**
* The URL to redirect to if not allowed
*
* @var string
*/
public $denied_url;
/**
* Must we be able to identify a valid contact
*
* @var bool
*/
public $contact_required;
/**
* The name of the form processor to trigger.
*
* @var string
*/
public $form_processor_name;
/**
* JSON parameters (object of simple key:value pairs) for the form processor
*
* @var text
*/
public $form_processor_params;
/**
* @var int
*/
public $use_count;
/**
* Access denied after this many uses
*
* @var int
*/
public $use_limit;
/**
* Access denied after this
*
* @var datetime
*/
public $use_by;
/**
* Class constructor.
*/
public function __construct() {
$this->__table = 'civicrm_action_link';
parent::__construct();
}
/**
* Returns all the column names of this table
*
* @return array
*/
public static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = [
'id' => [
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'description' => CRM_Actionlinks_ExtensionUtil::ts('Unique ActionLink ID'),
'required' => TRUE,
'where' => 'civicrm_action_link.id',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'name' => [
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Name'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('Administrative name'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_action_link.name',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'description' => [
'name' => 'description',
'type' => CRM_Utils_Type::T_TEXT,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Description'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('Description'),
'required' => FALSE,
'where' => 'civicrm_action_link.description',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'is_active' => [
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'description' => CRM_Actionlinks_ExtensionUtil::ts('Whether this link is active.'),
'where' => 'civicrm_action_link.is_active',
'default' => '0',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'allowed_url' => [
'name' => 'allowed_url',
'type' => CRM_Utils_Type::T_STRING,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Allowed Url'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('The URL you would normally redirect to'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_action_link.allowed_url',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'denied_url' => [
'name' => 'denied_url',
'type' => CRM_Utils_Type::T_STRING,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Denied Url'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('The URL to redirect to if not allowed'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_action_link.denied_url',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'contact_required' => [
'name' => 'contact_required',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Contact Required'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('Must we be able to identify a valid contact'),
'where' => 'civicrm_action_link.contact_required',
'default' => '1',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'form_processor_name' => [
'name' => 'form_processor_name',
'type' => CRM_Utils_Type::T_STRING,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Form Processor Name'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('The name of the form processor to trigger.'),
'required' => FALSE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_action_link.form_processor_name',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'form_processor_params' => [
'name' => 'form_processor_params',
'type' => CRM_Utils_Type::T_TEXT,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Form Processor Params'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('JSON parameters (object of simple key:value pairs) for the form processor'),
'required' => FALSE,
'where' => 'civicrm_action_link.form_processor_params',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
'serialize' => self::SERIALIZE_JSON,
],
'use_count' => [
'name' => 'use_count',
'type' => CRM_Utils_Type::T_INT,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Use Count'),
'where' => 'civicrm_action_link.use_count',
'default' => '0',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'use_limit' => [
'name' => 'use_limit',
'type' => CRM_Utils_Type::T_INT,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Use Limit'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('Access denied after this many uses'),
'required' => FALSE,
'where' => 'civicrm_action_link.use_limit',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
'use_by' => [
'name' => 'use_by',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => CRM_Actionlinks_ExtensionUtil::ts('Use By'),
'description' => CRM_Actionlinks_ExtensionUtil::ts('Access denied after this'),
'required' => FALSE,
'where' => 'civicrm_action_link.use_by',
'table_name' => 'civicrm_action_link',
'entity' => 'ActionLink',
'bao' => 'CRM_Actionlinks_DAO_ActionLink',
'localizable' => 0,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
public static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
public static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return bool
*/
public function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
public static function &import($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'action_link', $prefix, []);
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
public static function &export($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'action_link', $prefix, []);
return $r;
}
/**
* Returns the list of indices
*
* @param bool $localize
*
* @return array
*/
public static function indices($localize = TRUE) {
$indices = [];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}
<?php
use CRM_Actionlinks_ExtensionUtil as E;
/**
* Collection of upgrade steps.
*/
class CRM_Actionlinks_Upgrader extends CRM_Actionlinks_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Example: Run an external SQL script when the module is installed.
*
public function install() {
$this->executeSqlFile('sql/myinstall.sql');
}
/**
* Example: Work with entities usually not available during the install step.
*
* This method can be used for any post-install tasks. For example, if a step
* of your installation depends on accessing an entity that is itself
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*
public function postInstall() {
$customFieldId = civicrm_api3('CustomField', 'getvalue', array(
'return' => array("id"),
'name' => "customFieldCreatedViaManagedHook",
));
civicrm_api3('Setting', 'create', array(
'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
));
}
/**
* Example: Run an external SQL script when the module is uninstalled.
*
public function uninstall() {
$this->executeSqlFile('sql/myuninstall.sql');
}
/**
* Example: Run a simple query when a module is enabled.
*
public function enable() {
CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
}
/**
* Example: Run a simple query when a module is disabled.
*
public function disable() {
CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
}
/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*
public function upgrade_4200() {
$this->ctx->log->info('Applying update 4200');
CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
return TRUE;
} // */
/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
public function upgrade_4201() {
$this->ctx->log->info('Applying update 4201');
// this path is relative to the extension base dir
$this->executeSqlFile('sql/upgrade_4201.sql');
return TRUE;
} // */
/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
public function upgrade_4202() {
$this->ctx->log->info('Planning update 4202'); // PEAR Log interface
$this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
$this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
$this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
return TRUE;
}
public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
public function processPart3($arg5) { sleep(10); return TRUE; }
// */
/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
public function upgrade_4203() {
$this->ctx->log->info('Planning update 4203'); // PEAR Log interface
$minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
$maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
$endId = $startId + self::BATCH_SIZE - 1;
$title = E::ts('Upgrade Batch (%1 => %2)', array(
1 => $startId,
2 => $endId,
));
$sql = '
UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
WHERE id BETWEEN %1 and %2
';
$params = array(
1 => array($startId, 'Integer'),
2 => array($endId, 'Integer'),
);
$this->addTask($title, 'executeSql', $sql, $params);
}
return TRUE;
} // */
}
<?php
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
use CRM_Actionlinks_ExtensionUtil as E;
/**
* Base class which provides helpers to execute upgrade logic
*/
class CRM_Actionlinks_Upgrader_Base {
/**
* @var varies, subclass of this
*/
static $instance;
/**
* @var CRM_Queue_TaskContext
*/
protected $ctx;
/**
* @var string, eg 'com.example.myextension'
*/
protected $extensionName;
/**
* @var string, full path to the extension's source tree
*/
protected $extensionDir;
/**
* @var array(revisionNumber) sorted numerically
*/
private $revisions;
/**
* @var boolean
* Flag to clean up extension revision data in civicrm_setting
*/
private $revisionStorageIsDeprecated = FALSE;
/**
* Obtain a reference to the active upgrade handler.
*/
static public function instance() {
if (!self::$instance) {
// FIXME auto-generate
self::$instance = new CRM_Actionlinks_Upgrader(
'actionlinks',
realpath(__DIR__ . '/../../../')
);
}
return self::$instance;
}
/**
* Adapter that lets you add normal (non-static) member functions to the queue.
*
* Note: Each upgrader instance should only be associated with one
* task-context; otherwise, this will be non-reentrant.
*
* @code
* CRM_Actionlinks_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2');
* @endcode
*/
static public function _queueAdapter() {
$instance = self::instance();
$args = func_get_args();
$instance->ctx = array_shift($args);
$instance->queue = $instance->ctx->queue;
$method = array_shift($args);
return call_user_func_array(array($instance, $method), $args);
}
public function __construct($extensionName, $extensionDir) {
$this->extensionName = $extensionName;
$this->extensionDir = $extensionDir;
}
// ******** Task helpers ********
/**
* Run a CustomData file.
*
* @param string $relativePath the CustomData XML file path (relative to this extension's dir)
* @return bool
*/
public function executeCustomDataFile($relativePath) {
$xml_file = $this->extensionDir . '/' . $relativePath;
return $this->executeCustomDataFileByAbsPath($xml_file);
}
/**
* Run a CustomData file
*
* @param string $xml_file the CustomData XML file path (absolute path)
*
* @return bool
*/
protected static function executeCustomDataFileByAbsPath($xml_file) {
$import = new CRM_Utils_Migrate_Import();
$import->run($xml_file);
return TRUE;
}
/**
* Run a SQL file.
*
* @param string $relativePath the SQL file path (relative to this extension's dir)
*
* @return bool
*/
public function executeSqlFile($relativePath) {
CRM_Utils_File::sourceSQLFile(