diff --git a/core/modules/file/config/views.view.files.yml b/core/modules/file/config/views.view.files.yml index c11c4728459..8aaae34439f 100644 --- a/core/modules/file/config/views.view.files.yml +++ b/core/modules/file/config/views.view.files.yml @@ -71,7 +71,8 @@ display: filemime: filemime filesize: filesize status: status - timestamp: timestamp + created: created + changed: changed count: count info: fid: @@ -109,7 +110,14 @@ display: separator: '' empty_column: false responsive: priority-low - timestamp: + created: + sortable: true + default_sort_order: desc + align: '' + separator: '' + empty_column: false + responsive: '' + changed: sortable: true default_sort_order: desc align: '' @@ -123,7 +131,7 @@ display: separator: '' empty_column: false responsive: priority-medium - default: timestamp + default: changed empty_table: true row: type: fields @@ -340,10 +348,10 @@ display: empty_zero: false hide_alter_empty: true plugin_id: file_status - timestamp: - id: timestamp + created: + id: created table: file_managed - field: timestamp + field: created relationship: none group_type: group admin_label: '' @@ -392,6 +400,58 @@ display: custom_date_format: '' timezone: '' plugin_id: date + changed: + id: changed + table: file_managed + field: changed + relationship: none + group_type: group + admin_label: '' + label: 'Changed date' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: '' + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + date_format: medium + custom_date_format: '' + timezone: '' + plugin_id: date count: id: count table: file_usage diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php index 9ebbc95096f..ebc32aca95c 100644 --- a/core/modules/file/file.api.php +++ b/core/modules/file/file.api.php @@ -81,8 +81,8 @@ function hook_file_validate(Drupal\file\FileInterface $file) { * The file entity that is about to be created or updated. */ function hook_file_presave(Drupal\file\FileInterface $file) { - // Change the file timestamp to an hour prior. - $file->timestamp -= 3600; + // Change the owner of the file. + $file->uid->value = 1; } /** diff --git a/core/modules/file/file.install b/core/modules/file/file.install index c5ec889d916..8fd5a37bc8c 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -78,8 +78,15 @@ function file_schema() { 'default' => 0, 'size' => 'tiny', ), - 'timestamp' => array( - 'description' => 'UNIX timestamp for when the file was added.', + 'created' => array( + 'description' => 'UNIX timestamp for when the file added.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'changed' => array( + 'description' => 'UNIX timestamp for when the file was last changed.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, @@ -89,7 +96,7 @@ function file_schema() { 'indexes' => array( 'uid' => array('uid'), 'status' => array('status'), - 'timestamp' => array('timestamp'), + 'changed' => array('changed'), ), 'unique keys' => array( 'uuid' => array('uuid'), @@ -320,4 +327,3 @@ function file_update_8004() { ); db_change_field('file_managed', 'filesize', 'filesize', $spec); } - diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 1c1318893dd..892b214ef15 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1036,7 +1036,11 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr break; // These tokens are default variations on the chained tokens handled below. - case 'timestamp': + case 'created': + $replacements[$original] = format_date($file->getCreatedTime(), 'medium', '', NULL, $langcode); + break; + + case 'changed': $replacements[$original] = format_date($file->getChangedTime(), 'medium', '', NULL, $langcode); break; @@ -1047,7 +1051,11 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr } } - if ($date_tokens = $token_service->findWithPrefix($tokens, 'timestamp')) { + if ($date_tokens = $token_service->findWithPrefix($tokens, 'created')) { + $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->getCreatedTime()), $options); + } + + if ($date_tokens = $token_service->findWithPrefix($tokens, 'changed')) { $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->getChangedTime()), $options); } @@ -1094,8 +1102,13 @@ function file_token_info() { 'name' => t("URL"), 'description' => t("The web-accessible URL for the file."), ); - $file['timestamp'] = array( - 'name' => t("Timestamp"), + $file['created'] = array( + 'name' => t("Created"), + 'description' => t("The date the file created."), + 'type' => 'date', + ); + $file['changed'] = array( + 'name' => t("Changed"), 'description' => t("The date the file was most recently changed."), 'type' => 'date', ); diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index f78ec87a2ec..4e51a871efa 100644 --- a/core/modules/file/file.views.inc +++ b/core/modules/file/file.views.inc @@ -154,15 +154,30 @@ function file_views_data() { ), ); - // timestamp field - $data['file_managed']['timestamp'] = array( + // The created field. + $data['file_managed']['created'] = array( 'title' => t('Upload date'), 'help' => t('The date the file was uploaded.'), 'field' => array( 'id' => 'date', ), 'sort' => array( - 'id' => 'date' + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + ); + + // The changed field. + $data['file_managed']['changed'] = array( + 'title' => t('Modified date'), + 'help' => t('The date the file was last changed.'), + 'field' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', ), 'filter' => array( 'id' => 'date', diff --git a/core/modules/file/lib/Drupal/file/Entity/File.php b/core/modules/file/lib/Drupal/file/Entity/File.php index a88207eea0f..816435b6710 100644 --- a/core/modules/file/lib/Drupal/file/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Entity/File.php @@ -108,11 +108,18 @@ class File extends ContentEntityBase implements FileInterface { $this->get('filesize')->value = $size; } + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + return $this->get('created')->value; + } + /** * {@inheritdoc} */ public function getChangedTime() { - return $this->get('timestamp')->value; + return $this->get('changed')->value; } /** @@ -178,7 +185,11 @@ class File extends ContentEntityBase implements FileInterface { public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); - $this->timestamp = REQUEST_TIME; + $this->changed->value = REQUEST_TIME; + if (empty($this->created->value)) { + $this->created->value = REQUEST_TIME; + } + $this->setSize(filesize($this->getFileUri())); if (!isset($this->langcode->value)) { // Default the file's language code to none, because files are language @@ -253,9 +264,13 @@ class File extends ContentEntityBase implements FileInterface { ->setLabel(t('Status')) ->setDescription(t('The status of the file, temporary (0) and permanent (1).')); - $fields['timestamp'] = FieldDefinition::create('integer') + $fields['created'] = FieldDefinition::create('integer') ->setLabel(t('Created')) - ->setDescription(t('The time that the node was created.')); + ->setDescription(t('The timestamp that the file was created.')); + + $fields['changed'] = FieldDefinition::create('integer') + ->setLabel(t('Changed')) + ->setDescription(t('The timestamp that the file was last changed.')); return $fields; } diff --git a/core/modules/file/lib/Drupal/file/FileInterface.php b/core/modules/file/lib/Drupal/file/FileInterface.php index 73783efcacf..c4fd9f0f3cd 100644 --- a/core/modules/file/lib/Drupal/file/FileInterface.php +++ b/core/modules/file/lib/Drupal/file/FileInterface.php @@ -127,4 +127,11 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface { */ public function setOwner(UserInterface $user); + /** + * Returns the node creation timestamp. + * + * @return int + * Creation timestamp of the node. + */ + public function getCreatedTime(); } diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php index 15cf0366276..1c0a3f133fb 100644 --- a/core/modules/file/lib/Drupal/file/FileStorageController.php +++ b/core/modules/file/lib/Drupal/file/FileStorageController.php @@ -33,9 +33,9 @@ class FileStorageController extends FieldableDatabaseStorageController implement public function retrieveTemporaryFiles() { // Use separate placeholders for the status to avoid a bug in some versions // of PHP. See http://drupal.org/node/352956. - return $this->database->query('SELECT fid FROM {' . $this->entityInfo->getBaseTable() . '} WHERE status <> :permanent AND timestamp < :timestamp', array( + return $this->database->query('SELECT fid FROM {' . $this->entityInfo->getBaseTable() . '} WHERE status <> :permanent AND changed < :changed', array( ':permanent' => FILE_STATUS_PERMANENT, - ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE + ':changed' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE )); } } diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php index 6cdf557dc33..00fb296eeb0 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php @@ -23,7 +23,7 @@ class File extends WizardPluginBase { /** * Set the created column. */ - protected $createdColumn = 'timestamp'; + protected $createdColumn = 'created'; /** * Set default values for the path field options. diff --git a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php index c6486fee910..9d1911b7928 100644 --- a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php @@ -65,7 +65,7 @@ class DeleteTest extends FileManagedTestBase { // of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. db_update('file_managed') ->fields(array( - 'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), + 'changed' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), )) ->condition('fid', $file->id()) ->execute(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index d54e596316c..84bfd343f4a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -119,7 +119,7 @@ class FileFieldRevisionTest extends FileFieldTestBase { // of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. db_update('file_managed') ->fields(array( - 'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), + 'changed' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), )) ->condition('fid', $node_file_r3->id()) ->execute(); @@ -134,7 +134,7 @@ class FileFieldRevisionTest extends FileFieldTestBase { // of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. db_update('file_managed') ->fields(array( - 'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), + 'changed' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), )) ->condition('fid', $node_file_r1->id()) ->execute(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php b/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php index 5582ce358ad..dd274846383 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileListingTest.php @@ -158,7 +158,8 @@ class FileListingTest extends FileFieldTestBase { 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', - 'timestamp' => 1, + 'created' => 1, + 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, )); file_put_contents($file->getFileUri(), 'hello world'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php index b6fb820fd1f..85ee55358eb 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php @@ -111,7 +111,8 @@ abstract class FileManagedTestBase extends FileTestBase { $file->filename = drupal_basename($file->uri); $file->filemime = 'text/plain'; $file->uid = 1; - $file->timestamp = REQUEST_TIME; + $file->created = REQUEST_TIME; + $file->changed = REQUEST_TIME; $file->filesize = filesize($file->uri); $file->status = 0; // Write the record directly rather than using the API so we don't invoke diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 924c2b903de..9e0039dc5dd 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -53,8 +53,10 @@ class FileTokenReplaceTest extends FileFieldTestBase { $tests['[file:mime]'] = check_plain($file->getMimeType()); $tests['[file:size]'] = format_size($file->getSize()); $tests['[file:url]'] = check_plain(file_create_url($file->getFileUri())); - $tests['[file:timestamp]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id); - $tests['[file:timestamp:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id); + $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->id); + $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->id); + $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id); + $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id); $tests['[file:owner]'] = check_plain(user_format_name($this->admin_user)); $tests['[file:owner:uid]'] = $file->getOwner()->id(); diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php index 476110561b9..4c3b0c0f69e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php @@ -28,7 +28,8 @@ class SaveTest extends FileManagedTestBase { 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', - 'timestamp' => 1, + 'created' => 1, + 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, )); file_put_contents($file->getFileUri(), 'hello world'); @@ -70,7 +71,8 @@ class SaveTest extends FileManagedTestBase { 'filename' => 'DRUPLICON.txt', 'uri' => 'public://DRUPLICON.txt', 'filemime' => 'text/plain', - 'timestamp' => 1, + 'created' => 1, + 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, )); file_put_contents($file->getFileUri(), 'hello world'); diff --git a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php index c4b053c65da..5ce7937ab3e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php @@ -134,7 +134,7 @@ class UsageTest extends FileManagedTestBase { db_update('file_managed') ->fields(array( 'status' => 0, - 'timestamp' => 1, + 'changed' => 1, )) ->condition('fid', $temp_old->id()) ->execute(); @@ -151,7 +151,7 @@ class UsageTest extends FileManagedTestBase { // Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. $perm_old = file_save_data(''); db_update('file_managed') - ->fields(array('timestamp' => 1)) + ->fields(array('changed' => 1)) ->condition('fid', $temp_old->id()) ->execute(); $this->assertTrue(file_exists($perm_old->getFileUri()), 'Old permanent file was created correctly.'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index e7cf6746530..784b0acee5d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -224,7 +224,8 @@ class EntityCrudHookTest extends EntityUnitTestBase { 'filemime' => 'text/plain', 'filesize' => filesize($url), 'status' => 1, - 'timestamp' => REQUEST_TIME, + 'created' => REQUEST_TIME, + 'changed' => REQUEST_TIME, )); $this->assertHookMessageOrder(array( diff --git a/core/modules/system/tests/upgrade/drupal-7.language.database.php b/core/modules/system/tests/upgrade/drupal-7.language.database.php index ab8a81622ff..80253546b25 100644 --- a/core/modules/system/tests/upgrade/drupal-7.language.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.language.database.php @@ -776,7 +776,8 @@ db_insert('file_managed')->fields(array( 'filemime', 'filesize', 'status', - 'timestamp' + 'created', + 'changed', )) ->values(array( 'fid' => '1', @@ -786,6 +787,7 @@ db_insert('file_managed')->fields(array( 'filemime' => 'text/plain', 'filesize' => 0, 'status' => 1, - 'timestamp' => '1314997642', + 'created' => '1314997642', + 'changed' => '1314997642', )) ->execute(); diff --git a/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php b/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php index 12d2b2e6a83..54ea2d850db 100644 --- a/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.user_picture.database.php @@ -19,7 +19,8 @@ $fid = db_insert('file_managed') 'filename' => 'faked_image.png', 'filesize' => 1000, 'filemime' => 'image/png', - 'timestamp' => 1353542634, + 'created' => 1353542634, + 'changed' => 1353542634, )) ->execute(); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index fa88502161d..6363a91e822 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -69,7 +69,7 @@ class UserPictureTest extends WebTestBase { // of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. db_update('file_managed') ->fields(array( - 'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), + 'changed' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1), )) ->condition('fid', $file->id()) ->execute(); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index a194b00762a..4d7393558ab 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -555,7 +555,8 @@ function user_update_8011() { 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'filesize' => filesize($destination), 'filemime' => file_get_mimetype($destination), - 'timestamp' => REQUEST_TIME, + 'created' => REQUEST_TIME, + 'changed' => REQUEST_TIME, )) ->execute(); $default_image_fid = db_query('SELECT fid FROM {file_managed} WHERE uri = :uri', array(':uri' => $destination))->fetchField();