CRM-19948: Add The created_id field to File
authorDavi Alexandre <davi@davialexandre.com.br>
Wed, 8 Mar 2017 20:40:04 +0000 (17:40 -0300)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Tue, 22 May 2018 19:42:21 +0000 (01:12 +0530)
CRM/Core/DAO/AllCoreTables.data.php
CRM/Core/DAO/File.php
CRM/Upgrade/Incremental/php/FourSeven.php
xml/schema/Core/File.xml

index 730aadb7b03f510770cab326808b27b40579fd9e..e420a2d2264d80bf1e4ad0e71cd35207e22b2e4a 100644 (file)
@@ -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',
index fda3bc4e97775a6a787f8e648c31cf500abe0c01..107d9aad9b257b173d5c17157d6a64d2e2fb27bc 100644 (file)
@@ -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']);
     }
index 0f667a7c919ff74bc03008beda9439e66db1ef98..d45078e584cac9ffc4f07bb1da8521408878a1b4 100644 (file)
@@ -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;
   }
 
index b11c3da0f600a0a7c6efc809550c96d75ff057c6..2ba4b864f53bab5497cbe14c113da1d48c839e4c 100644 (file)
     <comment>Date and time that this attachment was uploaded or written to server.</comment>
     <add>1.5</add>
   </field>
+  <field>
+    <name>created_id</name>
+    <type>int unsigned</type>
+    <title>Created By Contact ID</title>
+    <comment>FK to civicrm_contact, who uploaded this file</comment>
+    <add>4.7</add>
+  </field>
+  <foreignKey>
+    <name>created_id</name>
+    <table>civicrm_contact</table>
+    <key>id</key>
+    <add>4.7</add>
+    <onDelete>SET NULL</onDelete>
+  </foreignKey>
 </table>