From ae6e7af65a094dbed061825121a662afe708d059 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 9 Nov 2014 22:33:28 -0800 Subject: [PATCH] Issue #2372201 by chx: Fixed FakeDelete is missing. --- .../Database/Driver/fake/FakeConnection.php | 7 ++ .../Core/Database/Driver/fake/FakeDelete.php | 79 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 core/lib/Drupal/Core/Database/Driver/fake/FakeDelete.php diff --git a/core/lib/Drupal/Core/Database/Driver/fake/FakeConnection.php b/core/lib/Drupal/Core/Database/Driver/fake/FakeConnection.php index 5738ab342a3..1be5147fe86 100644 --- a/core/lib/Drupal/Core/Database/Driver/fake/FakeConnection.php +++ b/core/lib/Drupal/Core/Database/Driver/fake/FakeConnection.php @@ -87,6 +87,13 @@ class FakeConnection extends Connection { return new FakeUpdate($this->databaseContents, $table); } + /** + * {@inheritdoc} + */ + public function delete($table, array $options = array()) { + return new FakeDelete($this->databaseContents, $table); + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Database/Driver/fake/FakeDelete.php b/core/lib/Drupal/Core/Database/Driver/fake/FakeDelete.php new file mode 100644 index 00000000000..4a75bfb2394 --- /dev/null +++ b/core/lib/Drupal/Core/Database/Driver/fake/FakeDelete.php @@ -0,0 +1,79 @@ +databaseContents = &$database_contents; + $this->table = $table; + $this->condition = new Condition('AND'); + } + + /** + * {@inheritdoc} + */ + public function execute() { + $affected = 0; + if (isset($this->databaseContents[$this->table])) { + $original_row_count = count($this->databaseContents[$this->table]); + $condition = $this->condition; + $this->databaseContents[$this->table] = array_filter($this->databaseContents[$this->table], function ($row_array) use ($condition) { + $row = new DatabaseRow($row_array); + return !ConditionResolver::matchGroup($row, $condition); + }); + $affected = $original_row_count - count($this->databaseContents[$this->table]); + } + return $affected; + } + + /** + * {@inheritdoc} + */ + public function exists(SelectInterface $select) { + throw new \Exception(sprintf('Method "%s" is not supported', __METHOD__)); + } + + /** + * {@inheritdoc} + */ + public function where($snippet, $args = array()) { + throw new \Exception(sprintf('Method "%s" is not supported', __METHOD__)); + } + +}