Skip to content
Snippets Groups Projects
Unverified Commit d4fae014 authored by DaveD's avatar DaveD Committed by GitHub
Browse files

Merge pull request #32332 from colemanw/upload_date

File - set default in sql for upload_date
parents 71268228 cb4958ec
Branches
Tags
No related merge requests found
......@@ -29,6 +29,38 @@ class CRM_Upgrade_Incremental_php_SixTwo extends CRM_Upgrade_Incremental_Base {
*/
public function upgrade_6_2_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Set upload_date in file table', 'setFileUploadDate');
$this->addTask('Set default for upload_date in file table', 'alterSchemaField', 'File', 'upload_date', [
'title' => ts('File Upload Date'),
'sql_type' => 'datetime',
'input_type' => 'Select Date',
'required' => TRUE,
'readonly' => TRUE,
'default' => 'CURRENT_TIMESTAMP',
'description' => ts('Date and time that this attachment was uploaded or written to server.'),
]);
}
public static function setFileUploadDate(): bool {
$sql = 'SELECT id, uri FROM civicrm_file WHERE upload_date IS NULL';
$dao = CRM_Core_DAO::executeQuery($sql);
$dir = CRM_Core_Config::singleton()->customFileUploadDir;
while ($dao->fetch()) {
$fileCreatedDate = time();
if ($dao->uri) {
$filePath = $dir . $dao->uri;
// Get created date from file if possible
if (is_file($filePath)) {
$fileCreatedDate = filectime($filePath);
}
}
CRM_Core_DAO::executeQuery('UPDATE civicrm_file SET upload_date = %1 WHERE id = %2', [
1 => [date('YmdHis', $fileCreatedDate), 'Date'],
2 => [$dao->id, 'Integer'],
]);
}
return TRUE;
}
}
......@@ -64,6 +64,9 @@ return [
'title' => ts('File Upload Date'),
'sql_type' => 'datetime',
'input_type' => 'Select Date',
'required' => TRUE,
'readonly' => TRUE,
'default' => 'CURRENT_TIMESTAMP',
'description' => ts('Date and time that this attachment was uploaded or written to server.'),
'add' => '1.5',
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment