Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
5c16622a
Commit
5c16622a
authored
Dec 13, 2012
by
catch
Browse files
Issue
#1851180
by heyrocker: Add deleteAll() function to Drupal\Core\Config\StorageInterface.
parent
79eaae2b
Changes
7
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Config/CachedStorage.php
View file @
5c16622a
...
...
@@ -141,4 +141,18 @@ public function decode($raw) {
public
function
listAll
(
$prefix
=
''
)
{
return
$this
->
storage
->
listAll
(
$prefix
);
}
/**
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
*/
public
function
deleteAll
(
$prefix
=
''
)
{
// If the cache was the first to be deleted, another process might start
// rebuilding the cache before the storage is renamed.
$cids
=
$this
->
storage
->
listAll
(
$prefix
);
if
(
$this
->
storage
->
deleteAll
(
$prefix
))
{
$this
->
cache
->
deleteMultiple
(
$cids
);
return
TRUE
;
}
return
FALSE
;
}
}
core/lib/Drupal/Core/Config/DatabaseStorage.php
View file @
5c16622a
...
...
@@ -160,4 +160,18 @@ public function listAll($prefix = '') {
':name'
=>
db_like
(
$prefix
)
.
'%'
,
),
$this
->
options
)
->
fetchCol
();
}
/**
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
*
* @throws PDOException
* @throws Drupal\Core\Database\DatabaseExceptionWrapper
* Only thrown in case $this->options['throw_exception'] is TRUE.
*/
public
function
deleteAll
(
$prefix
=
''
)
{
$options
=
array
(
'return'
=>
Database
::
RETURN_AFFECTED
)
+
$this
->
options
;
return
(
bool
)
$this
->
connection
->
delete
(
$this
->
table
,
$options
)
->
condition
(
'name'
,
$prefix
.
'%'
,
'LIKE'
)
->
execute
();
}
}
core/lib/Drupal/Core/Config/FileStorage.php
View file @
5c16622a
...
...
@@ -196,4 +196,19 @@ public function listAll($prefix = '') {
};
return
array_map
(
$clean_name
,
$files
);
}
/**
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
*/
public
function
deleteAll
(
$prefix
=
''
)
{
$success
=
TRUE
;
$files
=
$this
->
listAll
(
$prefix
);
foreach
(
$files
as
$name
)
{
if
(
!
$this
->
delete
(
$name
)
&&
$success
)
{
$success
=
FALSE
;
}
}
return
$success
;
}
}
core/lib/Drupal/Core/Config/InstallStorage.php
View file @
5c16622a
...
...
@@ -92,4 +92,14 @@ public function rename($name, $new_name) {
public
function
listAll
(
$prefix
=
''
)
{
throw
new
StorageException
(
'List operation is not allowed during install.'
);
}
/**
* Overrides Drupal\Core\Config\FileStorage::deleteAll().
*
* @throws Drupal\Core\Config\StorageException
*/
public
function
deleteAll
(
$prefix
=
''
)
{
throw
new
StorageException
(
'Delete operation is not allowed during install.'
);
}
}
core/lib/Drupal/Core/Config/NullStorage.php
View file @
5c16622a
...
...
@@ -78,4 +78,11 @@ public function decode($raw) {
public
function
listAll
(
$prefix
=
''
)
{
return
array
();
}
/**
* Implements Drupal\Core\Config\StorageInterface::deleteAll().
*/
public
function
deleteAll
(
$prefix
=
''
)
{
return
FALSE
;
}
}
core/lib/Drupal/Core/Config/StorageInterface.php
View file @
5c16622a
...
...
@@ -121,4 +121,24 @@ public function decode($raw);
* An array containing matching configuration object names.
*/
public
function
listAll
(
$prefix
=
''
);
/**
* Deletes configuration objects whose names start with a given prefix.
*
* Given the following configuration object names:
* - node.type.article
* - node.type.page
*
* Passing the prefix 'node.type.' will delete the above configuration
* objects.
*
* @param string $prefix
* (optional) The prefix to search for. If omitted, all configuration
* objects that exist will be deleted.
*
* @return boolean
* TRUE on success, FALSE otherwise.
*/
public
function
deleteAll
(
$prefix
=
''
);
}
core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php
View file @
5c16622a
...
...
@@ -92,8 +92,24 @@ function testCRUD() {
$this
->
assertIdentical
(
$result
,
FALSE
);
// Reading from a non-existing storage bin returns FALSE.
$data
=
$this
->
invalidStorage
->
read
(
$name
);
$this
->
assertIdentical
(
$data
,
FALSE
);
$result
=
$this
->
invalidStorage
->
read
(
$name
);
$this
->
assertIdentical
(
$result
,
FALSE
);
// Deleting all names with prefix deletes the appropriate data and returns
// TRUE.
$files
=
array
(
'config_test.test.biff'
,
'config_test.test.bang'
,
'config_test.test.pow'
,
);
foreach
(
$files
as
$name
)
{
$this
->
storage
->
write
(
$name
,
$data
);
}
$result
=
$this
->
storage
->
deleteAll
(
'config_test.'
);
$names
=
$this
->
storage
->
listAll
(
'config_test.'
);
$this
->
assertIdentical
(
$result
,
TRUE
);
$this
->
assertIdentical
(
$names
,
array
());
// Writing to a non-existing storage bin throws an exception.
try
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment