Skip to content

Commit

Permalink
generated DAO file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Feb 28, 2018
1 parent a4d6fac commit a3f143e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
11 changes: 7 additions & 4 deletions CRM/Core/DAO/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/File.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:c0230af2b9234e9f83dca829a0490cf3)
* (GenCodeChecksum:7fd8d2643aa05e33a38983f719c09111)
*/

/**
Expand Down Expand Up @@ -83,6 +83,7 @@ class CRM_Core_DAO_File extends CRM_Core_DAO {
* @var int unsigned
*/
public $created_id;

/**
* Class constructor.
*/
Expand All @@ -97,14 +98,15 @@ public function __construct() {
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
public 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');
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
*
Expand Down Expand Up @@ -193,11 +195,12 @@ public static function &fields() {
'created_id' => [
'name' => 'created_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Created By Contact ID') ,
'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',
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Contact',
],
];
Expand Down
10 changes: 3 additions & 7 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ public function upgrade_4_7_31($rev) {
*/
public function upgrade_4_7_32($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);

$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');
Expand Down Expand Up @@ -1415,14 +1414,11 @@ public static function civiMailingCreatedDateNull(CRM_Queue_TaskContext $ctx) {
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_BAO_SchemaHandler::safeRemoveFK('civicrm_file', 'FK_civicrm_file_created_id');

CRM_Core_DAO::executeQuery("
ALTER TABLE `{$fileTable}`
ADD CONSTRAINT `{$fkName}`
ALTER TABLE `civicrm_file`
ADD CONSTRAINT `FK_civicrm_file_created_id`
FOREIGN KEY (`created_id`)
REFERENCES `civicrm_contact`(`id`)
ON DELETE SET NULL
Expand Down
62 changes: 32 additions & 30 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/phpunit/CRM/Dedupe/MergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ public function getStaticCIDRefs() {
'civicrm_website' => array(
0 => 'contact_id',
),
'civicrm_file' => array(
0 => 'created_id',
),
);
}

Expand Down
10 changes: 7 additions & 3 deletions tests/phpunit/api/v3/AttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ public function testCreateWithWeirdName() {
$this->assertEquals('fa-file-text-o', $createResult['values'][$fileId]['icon']);
}

/**
* If one submits a file, it should be automatically store the logged in contact ID.
* This test ensure that there is always a creator ID of file upload
*/
public function testCreateShouldSetCreatedIdAsTheLoggedInUser() {
$loggedInUser = $this->createLoggedInUser();

Expand Down Expand Up @@ -473,11 +477,11 @@ public function testCreateShouldNotUpdateTheCreatedId() {

$this->callAPISuccess('Attachment', 'create', $attachmentParams);

$updatedAttachment = $this->callAPISuccess('Attachment', 'get', array(
$updatedAttachment = $this->callAPISuccess('Attachment', 'get', [
'id' => $fileId,
'entity_id' => $attachmentParams['entity_id'],
'entity_table' => $attachmentParams['entity_table']
));
'entity_table' => $attachmentParams['entity_table'],
]);

$this->assertNotEmpty($loggedInUser);
$this->assertEmpty($updatedAttachment['values'][$fileId]['created_id']);
Expand Down

0 comments on commit a3f143e

Please sign in to comment.