diff --git a/CRM/ACL/DAO/ACL.php b/CRM/ACL/DAO/ACL.php index 19960049f0fa..c1da86fa3757 100644 --- a/CRM/ACL/DAO/ACL.php +++ b/CRM/ACL/DAO/ACL.php @@ -12,149 +12,7 @@ /** * Database access object for the ACL entity. */ -class CRM_ACL_DAO_ACL extends CRM_Core_DAO { - const EXT = 'civicrm'; - const TABLE_ADDED = '1.6'; - - /** - * Static instance to hold the table name. - * - * @var string - */ - public static $_tableName = 'civicrm_acl'; - - /** - * Should CiviCRM log any modifications to this table in the civicrm_log table. - * - * @var bool - */ - public static $_log = FALSE; - - /** - * Paths for accessing this entity in the UI. - * - * @var string[] - */ - protected static $_paths = [ - 'add' => 'civicrm/acl/edit?reset=1&action=add', - 'delete' => 'civicrm/acl/delete?reset=1&action=delete&id=[id]', - 'update' => 'civicrm/acl/edit?reset=1&action=edit&id=[id]', - 'browse' => 'civicrm/acl', - ]; - - /** - * Unique table ID - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $id; - - /** - * ACL Name. - * - * @var string|null - * (SQL type: varchar(64)) - * Note that values will be retrieved from the database as a string. - */ - public $name; - - /** - * Is this ACL entry Allow (0) or Deny (1) ? - * - * @var bool|string - * (SQL type: tinyint) - * Note that values will be retrieved from the database as a string. - */ - public $deny; - - /** - * Table of the object possessing this ACL entry (Contact, Group, or ACL Group) - * - * @var string - * (SQL type: varchar(64)) - * Note that values will be retrieved from the database as a string. - */ - public $entity_table; - - /** - * ID of the object possessing this ACL - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $entity_id; - - /** - * What operation does this ACL entry control? - * - * @var string - * (SQL type: varchar(8)) - * Note that values will be retrieved from the database as a string. - */ - public $operation; - - /** - * The table of the object controlled by this ACL entry - * - * @var string|null - * (SQL type: varchar(64)) - * Note that values will be retrieved from the database as a string. - */ - public $object_table; - - /** - * The ID of the object controlled by this ACL entry - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $object_id; - - /** - * If this is a grant/revoke entry, what table are we granting? - * - * @var string|null - * (SQL type: varchar(64)) - * Note that values will be retrieved from the database as a string. - */ - public $acl_table; - - /** - * ID of the ACL or ACL group being granted/revoked - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $acl_id; - - /** - * Is this property active? - * - * @var bool|string - * (SQL type: tinyint) - * Note that values will be retrieved from the database as a string. - */ - public $is_active; - - /** - * @var int|string - * (SQL type: int) - * Note that values will be retrieved from the database as a string. - */ - public $priority; - - /** - * Class constructor. - */ - public function __construct() { - $this->__table = 'civicrm_acl'; - parent::__construct(); - } +class CRM_ACL_DAO_ACL extends CRM_Core_DAO_Base { /** * Returns localized title of this entity. @@ -166,342 +24,4 @@ public static function getEntityTitle($plural = FALSE) { return $plural ? ts('ACLs') : ts('ACL'); } - /** - * 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, - 'title' => ts('ACL ID'), - 'description' => ts('Unique table ID'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.id', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Number', - ], - 'readonly' => TRUE, - 'add' => '1.6', - ], - 'name' => [ - 'name' => 'name', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('ACL Name'), - 'description' => ts('ACL Name.'), - 'maxlength' => 64, - 'size' => CRM_Utils_Type::BIG, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.name', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Text', - ], - 'add' => '1.6', - ], - 'deny' => [ - 'name' => 'deny', - 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('Deny ACL?'), - 'description' => ts('Is this ACL entry Allow (0) or Deny (1) ?'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.deny', - 'default' => '0', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Radio', - ], - 'add' => '1.6', - ], - 'entity_table' => [ - 'name' => 'entity_table', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('ACL Entity'), - 'description' => ts('Table of the object possessing this ACL entry (Contact, Group, or ACL Group)'), - 'required' => TRUE, - 'maxlength' => 64, - 'size' => CRM_Utils_Type::BIG, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.entity_table', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'add' => '1.6', - ], - 'entity_id' => [ - 'name' => 'entity_id', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Entity ID'), - 'description' => ts('ID of the object possessing this ACL'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.entity_id', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'DFKEntityColumn' => 'entity_table', - 'FKColumnName' => 'id', - 'pseudoconstant' => [ - 'optionGroupName' => 'acl_role', - 'optionEditPath' => 'civicrm/admin/options/acl_role', - ], - 'add' => '1.6', - ], - 'operation' => [ - 'name' => 'operation', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('ACL Operation'), - 'description' => ts('What operation does this ACL entry control?'), - 'required' => TRUE, - 'maxlength' => 8, - 'size' => CRM_Utils_Type::EIGHT, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.operation', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select', - ], - 'pseudoconstant' => [ - 'callback' => 'CRM_ACL_BAO_ACL::operation', - ], - 'add' => '1.6', - ], - 'object_table' => [ - 'name' => 'object_table', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('ACL Object'), - 'description' => ts('The table of the object controlled by this ACL entry'), - 'maxlength' => 64, - 'size' => CRM_Utils_Type::BIG, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.object_table', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select', - 'label' => ts("Type of Data"), - ], - 'pseudoconstant' => [ - 'callback' => 'CRM_ACL_BAO_ACL::getObjectTableOptions', - ], - 'add' => '1.6', - ], - 'object_id' => [ - 'name' => 'object_id', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('ACL Object ID'), - 'description' => ts('The ID of the object controlled by this ACL entry'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.object_id', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select', - 'label' => ts("Which Data"), - 'controlField' => 'object_table', - ], - 'pseudoconstant' => [ - 'callback' => 'CRM_ACL_BAO_ACL::getObjectIdOptions', - 'prefetch' => 'disabled', - ], - 'add' => '1.6', - ], - 'acl_table' => [ - 'name' => 'acl_table', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('ACL Table'), - 'description' => ts('If this is a grant/revoke entry, what table are we granting?'), - 'maxlength' => 64, - 'size' => CRM_Utils_Type::BIG, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.acl_table', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'add' => '1.6', - ], - 'acl_id' => [ - 'name' => 'acl_id', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('ACL Group ID'), - 'description' => ts('ID of the ACL or ACL group being granted/revoked'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.acl_id', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'add' => '1.6', - ], - 'is_active' => [ - 'name' => 'is_active', - 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('ACL Is Active?'), - 'description' => ts('Is this property active?'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.is_active', - 'default' => '1', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'CheckBox', - 'label' => ts("Enabled"), - ], - 'add' => '1.6', - ], - 'priority' => [ - 'name' => 'priority', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Priority'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_acl.priority', - 'default' => '0', - 'table_name' => 'civicrm_acl', - 'entity' => 'ACL', - 'bao' => 'CRM_ACL_BAO_ACL', - 'localizable' => 0, - 'html' => [ - 'type' => 'Number', - ], - 'add' => '5.64', - ], - ]; - CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); - } - return Civi::$statics[__CLASS__]['fields']; - } - - /** - * 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__, 'acl', $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__, 'acl', $prefix, []); - return $r; - } - - /** - * Returns the list of indices - * - * @param bool $localize - * - * @return array - */ - public static function indices($localize = TRUE) { - $indices = [ - 'index_acl_id' => [ - 'name' => 'index_acl_id', - 'field' => [ - 0 => 'acl_id', - ], - 'localizable' => FALSE, - 'sig' => 'civicrm_acl::0::acl_id', - ], - ]; - return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; - } - } diff --git a/CRM/Core/DAO/Base.php b/CRM/Core/DAO/Base.php new file mode 100644 index 000000000000..e667f1c54ae0 --- /dev/null +++ b/CRM/Core/DAO/Base.php @@ -0,0 +1,298 @@ +primaryKey->fieldName) && empty($definition->primaryKey->name)) { + return parent::getPrimaryKey(); + } + if (empty($definition->primaryKey->fieldName)) { + return [(string) $definition->primaryKey->name]; + } + $primaryKeys = []; + foreach ($definition->primaryKey->fieldName as $fieldName) { + $primaryKeys[] = (string) $fieldName; + } + return $primaryKeys; + } + + /** + * Returns system paths related to this entity (as defined in the xml schema) + * + * @return array + */ + public static function getEntityPaths(): array { + $definition = static::getEntityDefinition(); + return (array) ($definition->paths ?? []); + } + + /** + * Returns user-friendly description of this entity based on the xml table . + * + * @return string + */ + public static function getEntityDescription(): ?string { + $definition = static::getEntityDefinition(); + $description = (string) ($definition->comment ?? NULL); + return $description ? static::_ts($description) : NULL; + } + + /** + * Returns localized name of this table + * + * @return string + */ + public static function getTableName() { + $definition = static::getEntityDefinition(); + return (string) $definition->name; + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog(): bool { + $definition = $this::getEntityDefinition(); + $log = (string) ($definition->log ?? 'false'); + return strtolower($log) === 'true'; + } + + /** + * Returns all the column names of this table + * + * @return array + */ + public static function &fields() { + $fields = (Civi::$statics[static::class]['fields'] ??= static::getSchemaFields()); + return $fields; + } + + private static function getSchemaFields(): array { + $fields = []; + $definition = static::getEntityDefinition(); + $baoName = CRM_Core_DAO_AllCoreTables::getBAOClassName(static::class); + $primaryKey = (string) ($definition->primaryKey->name ?? ''); + + $foreignKeys = []; + foreach ($definition->foreignKey ?? [] as $fkXml) { + if (!empty($fkXml->drop)) { + $foreignKeys[(string) $fkXml->name] = [ + 'FKClassName' => CRM_Core_DAO_AllCoreTables::getClassForTable($fkXml->table), + 'FKColumnName' => (string) ($fkXml->key ?? 'id'), + ]; + } + } + foreach ($definition->dynamicForeignKey ?? [] as $dfkXml) { + if (!empty($dfkXml->drop)) { + $foreignKeys[(string) $dfkXml->idColumn] = [ + 'DFKEntityColumn' => (string) $dfkXml->typeColumn, + 'FKColumnName' => (string) ($dfkXml->key ?? 'id'), + ]; + } + } + + foreach ($definition->field ?? [] as $fieldXml) { + if (!empty($fieldXml->drop)) { + continue; + } + $fieldName = (string) $fieldXml->name; + $fieldTypeAttrs = CRM_Utils_Schema::getTypeAttributes($fieldXml); + $field = [ + 'name' => $fieldName, + 'type' => $fieldTypeAttrs['crmTypeValue'], + 'title' => static::_ts(((string) ($fieldXml->title ?? '')) ?: CRM_Utils_Schema::composeTitle($fieldName)), + ]; + if (!empty($fieldXml->comment)) { + $field['description'] = static::_ts((string) $fieldXml->comment); + } + if (strtolower((string) ($fieldXml->required ?? '')) === 'true') { + $field['required'] = TRUE; + } + if (!empty($fieldTypeAttrs['length'])) { + $field['maxlength'] = $fieldTypeAttrs['length']; + } + if (!empty($fieldTypeAttrs['precision'])) { + $field['precision'] = explode(',', $fieldTypeAttrs['precision']); + } + if (!empty($fieldTypeAttrs['size'])) { + $field['size'] = is_numeric($fieldTypeAttrs['size']) ? (int) $fieldTypeAttrs['size'] : constant($fieldTypeAttrs['size']); + } + if (isset($fieldTypeAttrs['rows'])) { + $field['rows'] = $fieldTypeAttrs['rows']; + } + if (isset($fieldTypeAttrs['cols'])) { + $field['cols'] = $fieldTypeAttrs['cols']; + } + $field['usage'] = CRM_Utils_Schema::getFieldUsage($fieldXml); + if ($field['usage']['import']) { + $field['import'] = TRUE; + } + $field['where'] = ((string) $definition->name) . ".$fieldName"; + if (!empty($fieldXml->headerPattern)) { + $field['headerPattern'] = (string) $fieldXml->headerPattern; + } + if (!empty($fieldXml->dataPattern)) { + $field['dataPattern'] = (string) $fieldXml->dataPattern; + } + if ($field['usage']['export'] || (!$field['usage']['export'] && $field['usage']['import'])) { + $field['export'] = $field['usage']['export']; + } + if (!empty($fieldXml->contactType)) { + $field['contactType'] = (string) $fieldXml->contactType; + } + if (!empty($fieldXml->rule)) { + $field['rule'] = (string) $fieldXml->rule; + } + $permission = CRM_Utils_Schema::getFieldPermission($fieldXml); + if ($permission) { + $field['permission'] = $permission; + } + if (isset($fieldXml->default)) { + // Default value in the xml may or may not be quoted + $default = trim((string) $fieldXml->default, '"\''); + $field['default'] = $default === 'NULL' ? NULL : $default; + } + $field['table_name'] = (string) $definition->name; + $field['entity'] = (string) ($definition->entity ?? $definition->class); + $field['bao'] = $baoName; + $field['localizable'] = (int) ($fieldXml->localizable ?? 0); + if (!empty($fieldXml->localize_context)) { + $field['localize_context'] = (string) $fieldXml->localize_context; + } + $field += $foreignKeys[$fieldName] ?? []; + if (!empty($fieldXml->component)) { + $field['component'] = (string) $fieldXml->component; + } + if (!empty($fieldXml->serialize)) { + $field['unique_title'] = constant('CRM_Core_DAO::SERIALIZE_' . $fieldXml->serialize); + } + if (!empty($fieldXml->uniqueTitle)) { + $field['unique_title'] = static::_ts((string) $fieldXml->uniqueTitle); + } + if (!empty($fieldXml->deprecated)) { + $field['deprecated'] = TRUE; + } + $html = CRM_Utils_Schema::getFieldHtml($fieldXml); + if ($html) { + $field['html'] = $html; + } + $pseudoconstant = CRM_Utils_Schema::getFieldPseudoconstant($fieldXml); + if ($pseudoconstant) { + $field['pseudoconstant'] = $pseudoconstant; + } + if ($fieldName === $primaryKey || !empty($fieldXml->readonly)) { + $field['readonly'] = TRUE; + } + $field['add'] = CRM_Utils_Schema::toString('add', $fieldXml); + $fieldKey = (string) ($fieldXml->uniqueName ?? $fieldName); + $fields[$fieldKey] = $field; + } + CRM_Core_DAO_AllCoreTables::invoke(static::class, 'fields_callback', $fields); + return $fields; + } + + private static function getEntityDefinition(): SimpleXMLElement { + if (!isset(Civi::$statics[static::class][__FUNCTION__])) { + [, $dir, , $name] = explode('_', static::class); + $reflection = new ReflectionClass(static::class); + $classDir = dirname($reflection->getFileName()); + $xmlFile = $classDir . "/../../../xml/schema/$dir/$name.xml"; + [$definition, $error] = CRM_Utils_XML::parseFile($xmlFile); + if ($error) { + throw new CRM_Core_Exception(static::class . ': ' . $error); + } + Civi::$statics[static::class][__FUNCTION__] = $definition; + } + return Civi::$statics[static::class][__FUNCTION__]; + } + + /** + * @inheritDoc + */ + public static function getEntityIcon(string $entityName, int $entityId = NULL): ?string { + $definition = static::getEntityDefinition(); + return isset($definition->icon) ? (string) $definition->icon : NULL; + } + + /** + * Returns the list of indices + * + * @param bool $localize + * + * @return array + */ + public static function indices(bool $localize = TRUE): array { + $definition = static::getEntityDefinition(); + $indices = []; + foreach ($definition->index ?? [] as $indexXml) { + if (!empty($indexXml->drop)) { + continue; + } + $index = [ + 'name' => (string) $indexXml->name, + 'field' => [], + 'localizable' => FALSE, + ]; + if (!empty($indexXml->unique)) { + $index['unique'] = TRUE; + } + // populate fields + foreach ($indexXml->fieldName as $field) { + $fieldName = (string) ($field); + $index['field'][] = $fieldName; + foreach ($definition->field as $fieldXml) { + if (((string) $fieldXml->name) === $fieldName && !empty($fieldXml->localizable)) { + $index['localizable'] = TRUE; + } + } + } + $index['sig'] = ((string) $definition->name) . '::' . ((int) ($index['unique'] ?? 0)) . '::' . implode('::', $index['field']); + $indices[$index['name']] = $index; + } + return ($localize && $indices) ? CRM_Core_DAO_AllCoreTables::multilingualize(static::class, $indices) : $indices; + } + + private static function _ts(string $str) { + $params = ['domain' => [self::getExtensionName(), NULL]]; + return _ts($str, $params); + } + + public static function getExtensionName(): ?string { + if (!isset(Civi::$statics[static::class][__FUNCTION__])) { + $reflection = new ReflectionClass(static::class); + $classDir = dirname($reflection->getFileName()); + $infoFile = $classDir . "/../../../info.xml"; + [$info, $error] = CRM_Utils_XML::parseFile($infoFile); + $extensionKey = $info ? ($info->attributes()->key ?? NULL) : NULL; + Civi::$statics[static::class][__FUNCTION__] = (string) ($extensionKey ?? 'civicrm'); + } + return Civi::$statics[static::class][__FUNCTION__]; + } + + /** + * @return string + * Version in which table was added + */ + protected static function getTableAddVersion(): string { + $definition = static::getEntityDefinition(); + return (string) ($definition->add ?? '1.0'); + } + +} diff --git a/CRM/Core/DAO/Email.php b/CRM/Core/DAO/Email.php index 9c0eed6e14e9..bcf96fc7db86 100644 --- a/CRM/Core/DAO/Email.php +++ b/CRM/Core/DAO/Email.php @@ -12,153 +12,7 @@ /** * Database access object for the Email entity. */ -class CRM_Core_DAO_Email extends CRM_Core_DAO { - const EXT = 'civicrm'; - const TABLE_ADDED = '1.1'; - - /** - * Static instance to hold the table name. - * - * @var string - */ - public static $_tableName = 'civicrm_email'; - - /** - * Icon associated with this entity. - * - * @var string - */ - public static $_icon = 'fa-envelope-o'; - - /** - * Field to show when displaying a record. - * - * @var string - */ - public static $_labelField = 'email'; - - /** - * Should CiviCRM log any modifications to this table in the civicrm_log table. - * - * @var bool - */ - public static $_log = TRUE; - - /** - * Unique Email ID - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $id; - - /** - * FK to Contact ID - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $contact_id; - - /** - * Which Location does this email belong to. - * - * @var int|string|null - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $location_type_id; - - /** - * Email address - * - * @var string|null - * (SQL type: varchar(254)) - * Note that values will be retrieved from the database as a string. - */ - public $email; - - /** - * Is this the primary email address - * - * @var bool|string - * (SQL type: tinyint) - * Note that values will be retrieved from the database as a string. - */ - public $is_primary; - - /** - * Is this the billing? - * - * @var bool|string - * (SQL type: tinyint) - * Note that values will be retrieved from the database as a string. - */ - public $is_billing; - - /** - * Implicit FK to civicrm_option_value where option_group = email_on_hold. - * - * @var int|string - * (SQL type: int unsigned) - * Note that values will be retrieved from the database as a string. - */ - public $on_hold; - - /** - * Is this address for bulk mail ? - * - * @var bool|string - * (SQL type: tinyint) - * Note that values will be retrieved from the database as a string. - */ - public $is_bulkmail; - - /** - * When the address went on bounce hold - * - * @var string|null - * (SQL type: datetime) - * Note that values will be retrieved from the database as a string. - */ - public $hold_date; - - /** - * When the address bounce status was last reset - * - * @var string|null - * (SQL type: datetime) - * Note that values will be retrieved from the database as a string. - */ - public $reset_date; - - /** - * Text formatted signature for the email. - * - * @var string|null - * (SQL type: text) - * Note that values will be retrieved from the database as a string. - */ - public $signature_text; - - /** - * HTML formatted signature for the email. - * - * @var string|null - * (SQL type: text) - * Note that values will be retrieved from the database as a string. - */ - public $signature_html; - - /** - * Class constructor. - */ - public function __construct() { - $this->__table = 'civicrm_email'; - parent::__construct(); - } +class CRM_Core_DAO_Email extends CRM_Core_DAO_Base { /** * Returns localized title of this entity. @@ -166,377 +20,8 @@ public function __construct() { * @param bool $plural * Whether to return the plural version of the title. */ - public static function getEntityTitle($plural = FALSE) { + public static function getEntityTitle($plural = FALSE): string { return $plural ? ts('Emails') : ts('Email'); } - /** - * 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, - 'title' => ts('Email ID'), - 'description' => ts('Unique Email ID'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.id', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Number', - ], - 'readonly' => TRUE, - 'add' => '1.1', - ], - 'contact_id' => [ - 'name' => 'contact_id', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Contact ID'), - 'description' => ts('FK to Contact ID'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.contact_id', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'FKClassName' => 'CRM_Contact_DAO_Contact', - 'FKColumnName' => 'id', - 'html' => [ - 'label' => ts("Contact"), - ], - 'add' => '2.0', - ], - 'location_type_id' => [ - 'name' => 'location_type_id', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('Email Location Type'), - 'description' => ts('Which Location does this email belong to.'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.location_type_id', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select', - ], - 'pseudoconstant' => [ - 'table' => 'civicrm_location_type', - 'keyColumn' => 'id', - 'labelColumn' => 'display_name', - ], - 'add' => '2.0', - ], - 'email' => [ - 'name' => 'email', - 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Email'), - 'description' => ts('Email address'), - 'maxlength' => 254, - 'size' => 30, - 'usage' => [ - 'import' => TRUE, - 'export' => TRUE, - 'duplicate_matching' => TRUE, - 'token' => FALSE, - ], - 'import' => TRUE, - 'where' => 'civicrm_email.email', - 'headerPattern' => '/e.?mail/i', - 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/', - 'export' => TRUE, - 'rule' => 'email', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Email', - ], - 'add' => '1.1', - ], - 'is_primary' => [ - 'name' => 'is_primary', - 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('Is Primary'), - 'description' => ts('Is this the primary email address'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.is_primary', - 'default' => '0', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Radio', - ], - 'add' => '1.1', - ], - 'is_billing' => [ - 'name' => 'is_billing', - 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('Is Billing Email?'), - 'description' => ts('Is this the billing?'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.is_billing', - 'default' => '0', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'add' => '2.0', - ], - 'on_hold' => [ - 'name' => 'on_hold', - 'type' => CRM_Utils_Type::T_INT, - 'title' => ts('On Hold'), - 'description' => ts('Implicit FK to civicrm_option_value where option_group = email_on_hold.'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => TRUE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.on_hold', - 'export' => TRUE, - 'default' => '0', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select', - ], - 'pseudoconstant' => [ - 'callback' => 'CRM_Core_PseudoConstant::emailOnHoldOptions', - ], - 'add' => '1.1', - ], - 'is_bulkmail' => [ - 'name' => 'is_bulkmail', - 'type' => CRM_Utils_Type::T_BOOLEAN, - 'title' => ts('Use for Bulk Mail'), - 'description' => ts('Is this address for bulk mail ?'), - 'required' => TRUE, - 'usage' => [ - 'import' => FALSE, - 'export' => TRUE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.is_bulkmail', - 'export' => TRUE, - 'default' => '0', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'add' => '1.9', - ], - 'hold_date' => [ - 'name' => 'hold_date', - 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, - 'title' => ts('Hold Date'), - 'description' => ts('When the address went on bounce hold'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.hold_date', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select Date', - 'formatType' => 'activityDateTime', - 'label' => ts("Hold Date"), - ], - 'readonly' => TRUE, - 'add' => '1.1', - ], - 'reset_date' => [ - 'name' => 'reset_date', - 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, - 'title' => ts('Reset Date'), - 'description' => ts('When the address bounce status was last reset'), - 'usage' => [ - 'import' => FALSE, - 'export' => FALSE, - 'duplicate_matching' => FALSE, - 'token' => FALSE, - ], - 'where' => 'civicrm_email.reset_date', - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'type' => 'Select Date', - 'formatType' => 'activityDateTime', - 'label' => ts("Reset Date"), - ], - 'add' => '1.1', - ], - 'signature_text' => [ - 'name' => 'signature_text', - 'type' => CRM_Utils_Type::T_TEXT, - 'title' => ts('Signature Text'), - 'description' => ts('Text formatted signature for the email.'), - 'usage' => [ - 'import' => TRUE, - 'export' => TRUE, - 'duplicate_matching' => TRUE, - 'token' => FALSE, - ], - 'import' => TRUE, - 'where' => 'civicrm_email.signature_text', - 'export' => TRUE, - 'default' => NULL, - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'label' => ts("Signature Text"), - ], - 'add' => '3.2', - ], - 'signature_html' => [ - 'name' => 'signature_html', - 'type' => CRM_Utils_Type::T_TEXT, - 'title' => ts('Signature Html'), - 'description' => ts('HTML formatted signature for the email.'), - 'usage' => [ - 'import' => TRUE, - 'export' => TRUE, - 'duplicate_matching' => TRUE, - 'token' => FALSE, - ], - 'import' => TRUE, - 'where' => 'civicrm_email.signature_html', - 'export' => TRUE, - 'default' => NULL, - 'table_name' => 'civicrm_email', - 'entity' => 'Email', - 'bao' => 'CRM_Core_BAO_Email', - 'localizable' => 0, - 'html' => [ - 'label' => ts("Signature HTML"), - ], - 'add' => '3.2', - ], - ]; - CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); - } - return Civi::$statics[__CLASS__]['fields']; - } - - /** - * 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__, 'email', $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__, 'email', $prefix, []); - return $r; - } - - /** - * Returns the list of indices - * - * @param bool $localize - * - * @return array - */ - public static function indices($localize = TRUE) { - $indices = [ - 'index_location_type' => [ - 'name' => 'index_location_type', - 'field' => [ - 0 => 'location_type_id', - ], - 'localizable' => FALSE, - 'sig' => 'civicrm_email::0::location_type_id', - ], - 'UI_email' => [ - 'name' => 'UI_email', - 'field' => [ - 0 => 'email', - ], - 'localizable' => FALSE, - 'sig' => 'civicrm_email::0::email', - ], - 'index_is_primary' => [ - 'name' => 'index_is_primary', - 'field' => [ - 0 => 'is_primary', - ], - 'localizable' => FALSE, - 'sig' => 'civicrm_email::0::is_primary', - ], - 'index_is_billing' => [ - 'name' => 'index_is_billing', - 'field' => [ - 0 => 'is_billing', - ], - 'localizable' => FALSE, - 'sig' => 'civicrm_email::0::is_billing', - ], - ]; - return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; - } - } diff --git a/tests/phpunit/CRM/Core/DAO/ACLTest.php b/tests/phpunit/CRM/Core/DAO/ACLTest.php new file mode 100644 index 000000000000..69c80b554737 --- /dev/null +++ b/tests/phpunit/CRM/Core/DAO/ACLTest.php @@ -0,0 +1,361 @@ +assertEquals('civicrm_acl', CRM_ACL_DAO_ACL::getTableName()); + $this->assertEquals('civicrm', CRM_ACL_DAO_ACL::getExtensionName()); + $aclBao = new CRM_ACL_DAO_ACL(); + $this->assertFalse($aclBao->getLog()); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testIndices(): void { + $expected = [ + 'index_acl_id' => [ + 'name' => 'index_acl_id', + 'field' => [ + 0 => 'acl_id', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_acl::0::acl_id', + ], + ]; + $this->assertEquals($expected, CRM_ACL_BAO_ACL::indices(FALSE)); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testLinks(): void { + $expected = [ + 'add' => 'civicrm/acl/edit?reset=1&action=add', + 'delete' => 'civicrm/acl/delete?reset=1&action=delete&id=[id]', + 'update' => 'civicrm/acl/edit?reset=1&action=edit&id=[id]', + 'browse' => 'civicrm/acl', + ]; + $actual = CRM_ACL_BAO_ACL::getEntityPaths(); + $this->assertEquals($expected, $actual); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testFields(): void { + $expected = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('ACL ID'), + 'description' => ts('Unique table ID'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.id', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => '1.6', + ], + 'name' => [ + 'name' => 'name', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('ACL Name'), + 'description' => ts('ACL Name.'), + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.name', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '1.6', + ], + 'deny' => [ + 'name' => 'deny', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Deny ACL?'), + 'description' => ts('Is this ACL entry Allow (0) or Deny (1) ?'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.deny', + 'default' => '0', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Radio', + ], + 'add' => '1.6', + ], + 'entity_table' => [ + 'name' => 'entity_table', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('ACL Entity'), + 'description' => ts('Table of the object possessing this ACL entry (Contact, Group, or ACL Group)'), + 'required' => TRUE, + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.entity_table', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'add' => '1.6', + ], + 'entity_id' => [ + 'name' => 'entity_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Entity ID'), + 'description' => ts('ID of the object possessing this ACL'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.entity_id', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'DFKEntityColumn' => 'entity_table', + 'FKColumnName' => 'id', + 'pseudoconstant' => [ + 'optionGroupName' => 'acl_role', + 'optionEditPath' => 'civicrm/admin/options/acl_role', + ], + 'add' => '1.6', + ], + 'operation' => [ + 'name' => 'operation', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('ACL Operation'), + 'description' => ts('What operation does this ACL entry control?'), + 'required' => TRUE, + 'maxlength' => 8, + 'size' => CRM_Utils_Type::EIGHT, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.operation', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_ACL_BAO_ACL::operation', + ], + 'add' => '1.6', + ], + 'object_table' => [ + 'name' => 'object_table', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('ACL Object'), + 'description' => ts('The table of the object controlled by this ACL entry'), + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.object_table', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + 'label' => ts("Type of Data"), + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_ACL_BAO_ACL::getObjectTableOptions', + ], + 'add' => '1.6', + ], + 'object_id' => [ + 'name' => 'object_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('ACL Object ID'), + 'description' => ts('The ID of the object controlled by this ACL entry'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.object_id', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + 'label' => ts("Which Data"), + 'controlField' => 'object_table', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_ACL_BAO_ACL::getObjectIdOptions', + 'prefetch' => 'disabled', + ], + 'add' => '1.6', + ], + 'acl_table' => [ + 'name' => 'acl_table', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('ACL Table'), + 'description' => ts('If this is a grant/revoke entry, what table are we granting?'), + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.acl_table', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'add' => '1.6', + ], + 'acl_id' => [ + 'name' => 'acl_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('ACL Group ID'), + 'description' => ts('ID of the ACL or ACL group being granted/revoked'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.acl_id', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'add' => '1.6', + ], + 'is_active' => [ + 'name' => 'is_active', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('ACL Is Active?'), + 'description' => ts('Is this property active?'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.is_active', + 'default' => '1', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'CheckBox', + 'label' => ts("Enabled"), + ], + 'add' => '1.6', + ], + 'priority' => [ + 'name' => 'priority', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Priority'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_acl.priority', + 'default' => '0', + 'table_name' => 'civicrm_acl', + 'entity' => 'ACL', + 'bao' => 'CRM_ACL_BAO_ACL', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'add' => '5.64', + ], + ]; + $actual = CRM_ACL_BAO_ACL::fields(); + $this->assertEquals($expected, $actual); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testImport(): void { + $expected = []; + $this->assertEquals($expected, CRM_ACL_BAO_ACL::import()); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testExport(): void { + $expected = []; + $this->assertEquals($expected, CRM_ACL_BAO_ACL::export()); + } + +} diff --git a/tests/phpunit/CRM/Core/DAO/EmailTest.php b/tests/phpunit/CRM/Core/DAO/EmailTest.php new file mode 100644 index 000000000000..0cb34558e257 --- /dev/null +++ b/tests/phpunit/CRM/Core/DAO/EmailTest.php @@ -0,0 +1,589 @@ +assertEquals('civicrm_email', CRM_Core_DAO_Email::getTableName()); + $this->assertEquals('civicrm', CRM_Core_DAO_Email::getExtensionName()); + $emailBao = new CRM_Core_DAO_Email(); + $this->assertTrue($emailBao->getLog()); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testDescription(): void { + $expected = 'Email information for a specific location.'; + $actual = CRM_Core_DAO_Email::getEntityDescription(); + $this->assertEquals($expected, $actual); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testIndices(): void { + $expected = [ + 'index_location_type' => [ + 'name' => 'index_location_type', + 'field' => [ + 0 => 'location_type_id', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_email::0::location_type_id', + ], + 'UI_email' => [ + 'name' => 'UI_email', + 'field' => [ + 0 => 'email', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_email::0::email', + ], + 'index_is_primary' => [ + 'name' => 'index_is_primary', + 'field' => [ + 0 => 'is_primary', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_email::0::is_primary', + ], + 'index_is_billing' => [ + 'name' => 'index_is_billing', + 'field' => [ + 0 => 'is_billing', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_email::0::is_billing', + ], + ]; + $this->assertEquals($expected, CRM_Core_BAO_Email::indices(FALSE)); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testFields(): void { + $expected = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Email ID'), + 'description' => ts('Unique Email ID'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.id', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => '1.1', + ], + 'contact_id' => [ + 'name' => 'contact_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Contact ID'), + 'description' => ts('FK to Contact ID'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.contact_id', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'FKClassName' => 'CRM_Contact_DAO_Contact', + 'FKColumnName' => 'id', + 'html' => [ + 'label' => ts("Contact"), + ], + 'add' => '2.0', + ], + 'location_type_id' => [ + 'name' => 'location_type_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Email Location Type'), + 'description' => ts('Which Location does this email belong to.'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.location_type_id', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'table' => 'civicrm_location_type', + 'keyColumn' => 'id', + 'labelColumn' => 'display_name', + ], + 'add' => '2.0', + ], + 'email' => [ + 'name' => 'email', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Email'), + 'description' => ts('Email address'), + 'maxlength' => 254, + 'size' => 30, + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.email', + 'headerPattern' => '/e.?mail/i', + 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/', + 'export' => TRUE, + 'rule' => 'email', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Email', + ], + 'add' => '1.1', + ], + 'is_primary' => [ + 'name' => 'is_primary', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Is Primary'), + 'description' => ts('Is this the primary email address'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.is_primary', + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Radio', + ], + 'add' => '1.1', + ], + 'is_billing' => [ + 'name' => 'is_billing', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Is Billing Email?'), + 'description' => ts('Is this the billing?'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.is_billing', + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'add' => '2.0', + ], + 'on_hold' => [ + 'name' => 'on_hold', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('On Hold'), + 'description' => ts('Implicit FK to civicrm_option_value where option_group = email_on_hold.'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => TRUE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.on_hold', + 'export' => TRUE, + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_PseudoConstant::emailOnHoldOptions', + ], + 'add' => '1.1', + ], + 'is_bulkmail' => [ + 'name' => 'is_bulkmail', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Use for Bulk Mail'), + 'description' => ts('Is this address for bulk mail ?'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => TRUE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.is_bulkmail', + 'export' => TRUE, + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'add' => '1.9', + ], + 'hold_date' => [ + 'name' => 'hold_date', + 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, + 'title' => ts('Hold Date'), + 'description' => ts('When the address went on bounce hold'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.hold_date', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select Date', + 'formatType' => 'activityDateTime', + 'label' => ts("Hold Date"), + ], + 'readonly' => TRUE, + 'add' => '1.1', + ], + 'reset_date' => [ + 'name' => 'reset_date', + 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, + 'title' => ts('Reset Date'), + 'description' => ts('When the address bounce status was last reset'), + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.reset_date', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select Date', + 'formatType' => 'activityDateTime', + 'label' => ts("Reset Date"), + ], + 'add' => '1.1', + ], + 'signature_text' => [ + 'name' => 'signature_text', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Text'), + 'description' => ts('Text formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_text', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature Text"), + ], + 'add' => '3.2', + ], + 'signature_html' => [ + 'name' => 'signature_html', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Html'), + 'description' => ts('HTML formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_html', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature HTML"), + ], + 'add' => '3.2', + ], + ]; + $actual = CRM_Core_BAO_Email::fields(); + $this->assertEquals($expected, $actual); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testImport(): void { + $expected = [ + 'email' => [ + 'name' => 'email', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Email'), + 'description' => ts('Email address'), + 'maxlength' => 254, + 'size' => 30, + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.email', + 'headerPattern' => '/e.?mail/i', + 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/', + 'export' => TRUE, + 'rule' => 'email', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Email', + ], + 'add' => '1.1', + ], + 'signature_text' => [ + 'name' => 'signature_text', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Text'), + 'description' => ts('Text formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_text', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature Text"), + ], + 'add' => '3.2', + ], + 'signature_html' => [ + 'name' => 'signature_html', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Html'), + 'description' => ts('HTML formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_html', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature HTML"), + ], + 'add' => '3.2', + ], + ]; + $this->assertEquals($expected, CRM_Core_BAO_Email::import()); + } + + /** + * Super-brittle test added while refactoring DAOs to use CRM_Core_DAO_Base. + * Probably should be dialed back or deleted once refactor is complete. + */ + public function testExport(): void { + $expected = [ + 'email' => [ + 'name' => 'email', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Email'), + 'description' => ts('Email address'), + 'maxlength' => 254, + 'size' => 30, + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.email', + 'headerPattern' => '/e.?mail/i', + 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/', + 'export' => TRUE, + 'rule' => 'email', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Email', + ], + 'add' => '1.1', + ], + 'signature_text' => [ + 'name' => 'signature_text', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Text'), + 'description' => ts('Text formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_text', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature Text"), + ], + 'add' => '3.2', + ], + 'signature_html' => [ + 'name' => 'signature_html', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Signature Html'), + 'description' => ts('HTML formatted signature for the email.'), + 'usage' => [ + 'import' => TRUE, + 'export' => TRUE, + 'duplicate_matching' => TRUE, + 'token' => FALSE, + ], + 'import' => TRUE, + 'where' => 'civicrm_email.signature_html', + 'export' => TRUE, + 'default' => NULL, + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'label' => ts("Signature HTML"), + ], + 'add' => '3.2', + ], + 'on_hold' => [ + 'name' => 'on_hold', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('On Hold'), + 'description' => ts('Implicit FK to civicrm_option_value where option_group = email_on_hold.'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => TRUE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.on_hold', + 'export' => TRUE, + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_PseudoConstant::emailOnHoldOptions', + ], + 'add' => '1.1', + ], + 'is_bulkmail' => [ + 'name' => 'is_bulkmail', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Use for Bulk Mail'), + 'description' => ts('Is this address for bulk mail ?'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => TRUE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_email.is_bulkmail', + 'export' => TRUE, + 'default' => '0', + 'table_name' => 'civicrm_email', + 'entity' => 'Email', + 'bao' => 'CRM_Core_BAO_Email', + 'localizable' => 0, + 'add' => '1.9', + ], + ]; + $this->assertEquals($expected, CRM_Core_BAO_Email::export()); + } + +}