From c3438d19632d2951dd4c4701b0911e29e97ca8af Mon Sep 17 00:00:00 2001 From: Davi Alexandre Date: Wed, 8 Mar 2017 17:40:04 -0300 Subject: [PATCH] CRM-19948: Add The created_id field to File --- CRM/Core/DAO/AllCoreTables.data.php | 32 +++++++++++------------ CRM/Core/DAO/File.php | 32 ++++++++++++++++++++++- CRM/Upgrade/Incremental/php/FourSeven.php | 22 ++++++++++++++++ xml/schema/Core/File.xml | 14 ++++++++++ 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/CRM/Core/DAO/AllCoreTables.data.php b/CRM/Core/DAO/AllCoreTables.data.php index 730aadb7b0..e420a2d226 100644 --- a/CRM/Core/DAO/AllCoreTables.data.php +++ b/CRM/Core/DAO/AllCoreTables.data.php @@ -11,13 +11,8 @@ return [ 'name' => 'Extension', 'class' => 'CRM_Core_DAO_Extension', 'table' => 'civicrm_extension', - ], - 'CRM_Core_DAO_File' => [ - 'name' => 'File', - 'class' => 'CRM_Core_DAO_File', - 'table' => 'civicrm_file', - ], - 'CRM_Core_DAO_LocationType' => [ + ) , + 'CRM_Core_DAO_LocationType' => array( 'name' => 'LocationType', 'class' => 'CRM_Core_DAO_LocationType', 'table' => 'civicrm_location_type', @@ -291,13 +286,13 @@ return [ 'name' => 'Email', 'class' => 'CRM_Core_DAO_Email', 'table' => 'civicrm_email', - ], - 'CRM_Core_DAO_EntityFile' => [ - 'name' => 'EntityFile', - 'class' => 'CRM_Core_DAO_EntityFile', - 'table' => 'civicrm_entity_file', - ], - 'CRM_Core_DAO_IM' => [ + ) , + 'CRM_Core_DAO_File' => array( + 'name' => 'File', + 'class' => 'CRM_Core_DAO_File', + 'table' => 'civicrm_file', + ) , + 'CRM_Core_DAO_IM' => array( 'name' => 'IM', 'class' => 'CRM_Core_DAO_IM', 'table' => 'civicrm_im', @@ -531,8 +526,13 @@ return [ 'name' => 'Discount', 'class' => 'CRM_Core_DAO_Discount', 'table' => 'civicrm_discount', - ], - 'CRM_Core_DAO_EntityTag' => [ + ) , + 'CRM_Core_DAO_EntityFile' => array( + 'name' => 'EntityFile', + 'class' => 'CRM_Core_DAO_EntityFile', + 'table' => 'civicrm_entity_file', + ) , + 'CRM_Core_DAO_EntityTag' => array( 'name' => 'EntityTag', 'class' => 'CRM_Core_DAO_EntityTag', 'table' => 'civicrm_entity_tag', diff --git a/CRM/Core/DAO/File.php b/CRM/Core/DAO/File.php index fda3bc4e97..107d9aad9b 100644 --- a/CRM/Core/DAO/File.php +++ b/CRM/Core/DAO/File.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/File.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:996b2702471b24fb13c740ef104ea1f9) + * (GenCodeChecksum:c0230af2b9234e9f83dca829a0490cf3) */ /** @@ -77,6 +77,12 @@ class CRM_Core_DAO_File extends CRM_Core_DAO { */ public $upload_date; + /** + * FK to civicrm_contact, who uploaded this file + * + * @var int unsigned + */ + public $created_id; /** * Class constructor. */ @@ -85,6 +91,20 @@ class CRM_Core_DAO_File extends CRM_Core_DAO { parent::__construct(); } + /** + * Returns foreign keys and entity references. + * + * @return array + * [CRM_Core_Reference_Interface] + */ + static function getReferenceColumns() { + if (!isset(Civi::$statics[__CLASS__]['links'])) { + Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__); + Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'created_id', 'civicrm_contact', 'id'); + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); + } + return Civi::$statics[__CLASS__]['links']; + } /** * Returns all the column names of this table * @@ -170,6 +190,16 @@ class CRM_Core_DAO_File extends CRM_Core_DAO { 'bao' => 'CRM_Core_BAO_File', 'localizable' => 0, ], + 'created_id' => [ + 'name' => 'created_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Created By Contact ID') , + 'description' => 'FK to civicrm_contact, who uploaded this file', + 'table_name' => 'civicrm_file', + 'entity' => 'File', + 'bao' => 'CRM_Core_BAO_File', + 'FKClassName' => 'CRM_Contact_DAO_Contact', + ], ]; CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 0f667a7c91..d45078e584 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -507,6 +507,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base $this->addTask('CRM-21733: Add status_override_end_date field to civicrm_membership table', 'addColumn', 'civicrm_membership', 'status_override_end_date', "date DEFAULT NULL COMMENT 'The end date of membership status override if (Override until selected date) override type is selected.'"); + $this->addTask('CRM-19948 - Add created_id column to civicrm_file', 'addFileCreatedIdColumn'); } /* @@ -1410,6 +1411,27 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_ $dataType = 'datetime'; } CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_mailing CHANGE created_date created_date {$dataType} NULL DEFAULT NULL COMMENT 'Date and time this mailing was created.'"); + + return TRUE; + } + + public static function addFileCreatedIdColumn(CRM_Queue_TaskContext $ctx) { + self::addColumn($ctx, 'civicrm_file', 'created_id', "int unsigned COMMENT 'FK to civicrm_contact, who uploaded this file'"); + + $fileTable = 'civicrm_file'; + $fkName = 'FK_civicrm_file_created_id'; + + CRM_Core_BAO_SchemaHandler::safeRemoveFK($fileTable, $fkName); + + CRM_Core_DAO::executeQuery(" + ALTER TABLE `{$fileTable}` + ADD CONSTRAINT `{$fkName}` + FOREIGN KEY (`created_id`) + REFERENCES `civicrm_contact`(`id`) + ON DELETE SET NULL + ON UPDATE CASCADE; + "); + return TRUE; } diff --git a/xml/schema/Core/File.xml b/xml/schema/Core/File.xml index b11c3da0f6..2ba4b864f5 100644 --- a/xml/schema/Core/File.xml +++ b/xml/schema/Core/File.xml @@ -64,4 +64,18 @@ Date and time that this attachment was uploaded or written to server. 1.5 + + created_id + int unsigned + Created By Contact ID + FK to civicrm_contact, who uploaded this file + 4.7 + + + created_id + civicrm_contact
+ id + 4.7 + SET NULL +
-- 2.25.1