Commit c503bb6a authored by alexpott's avatar alexpott

Issue #3014950 by goodboy, mondrake, alexpott: Replace all db calls to...

Issue #3014950 by goodboy, mondrake, alexpott: Replace all db calls to file_managed table with Entity APIs
parent d7999461
......@@ -59,7 +59,7 @@ public function getTestFile($type_name, $size = NULL) {
* Retrieves the fid of the last inserted file.
*/
public function getLastFileId() {
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
}
/**
......
......@@ -118,7 +118,8 @@ public function testRevisions() {
// Call file_cron() to clean up the file. Make sure the changed timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value.
// configuration value. We use an UPDATE statement because using the API
// would set the timestamp.
$connection = Database::getConnection();
$connection->update('file_managed')
->fields([
......@@ -135,7 +136,8 @@ public function testRevisions() {
$this->drupalPostForm('node/' . $nid . '/delete', [], t('Delete'));
// Call file_cron() to clean up the file. Make sure the changed timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value.
// configuration value. We use an UPDATE statement because using the API
// would set the timestamp.
$connection->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
......
......@@ -60,7 +60,7 @@ public function getTestFile($type_name, $size = NULL) {
* Retrieves the fid of the last inserted file.
*/
public function getLastFileId() {
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
}
/**
......
......@@ -66,7 +66,7 @@ protected function setUp() {
$this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
......@@ -89,7 +89,7 @@ protected function setUp() {
* Tests the _file_save_upload_from_form() function.
*/
public function testNormal() {
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
$file1 = File::load($max_fid_after);
$this->assertTrue($file1, 'Loaded the file.');
......@@ -107,7 +107,7 @@ public function testNormal() {
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('You WIN!'));
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
// Check that the correct hooks were called.
$this->assertFileHooksCalled(['validate', 'insert']);
......
......@@ -61,7 +61,7 @@ protected function setUp() {
$this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
$this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
// Upload with replace to guarantee there's something there.
$edit = [
......@@ -82,7 +82,7 @@ protected function setUp() {
* Test the file_save_upload() function.
*/
public function testNormal() {
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
$this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.');
$file1 = File::load($max_fid_after);
$this->assertTrue($file1, 'Loaded the file.');
......@@ -98,7 +98,7 @@ public function testNormal() {
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('You WIN!'));
$max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
$max_fid_after = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
// Check that the correct hooks were called.
$this->assertFileHooksCalled(['validate', 'insert']);
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\file\FunctionalJavascript;
use Drupal\Core\Database\Database;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
......@@ -95,7 +94,7 @@ public function testManagedFile() {
* Retrieves the fid of the last inserted file.
*/
protected function getLastFileId() {
return (int) Database::getConnection()->query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
}
}
......@@ -61,7 +61,8 @@ public function testInUse() {
// Call file_cron() to clean up the file. Make sure the changed timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value.
// configuration value. We use an UPDATE statement because using the API
// would set the timestamp.
Database::getConnection()->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
......
......@@ -109,7 +109,7 @@ public function uploadNodeImage($image, $field_name, $type, $alt = '') {
* Retrieves the fid of the last inserted file.
*/
protected function getLastFileId() {
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
}
}
......@@ -104,7 +104,7 @@ public function uploadNodeImage($image, $field_name, $type, $alt = '') {
* Retrieves the fid of the last inserted file.
*/
protected function getLastFileId() {
return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
}
}
......@@ -74,7 +74,8 @@ public function testCreateDeletePicture() {
// Call file_cron() to clean up the file. Make sure the timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value.
// configuration value. We use an UPDATE statement because using the API
// would set the timestamp.
Database::getConnection()->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment