public function backup_migrate_item::all_items in Backup and Migrate 7.3
Same name and namespace in other branches
- 8.2 includes/crud.inc \backup_migrate_item::all_items()
- 8.3 includes/crud.inc \backup_migrate_item::all_items()
- 6.3 includes/crud.inc \backup_migrate_item::all_items()
- 6.2 includes/crud.inc \backup_migrate_item::all_items()
- 7.2 includes/crud.inc \backup_migrate_item::all_items()
Get all of the given items.
3 calls to backup_migrate_item::all_items()
- backup_migrate_item::get_list in includes/
crud.inc - Get a table of all items of this type.
- backup_migrate_item::item in includes/
crud.inc - A particular item.
- backup_migrate_item::item_exists in includes/
crud.inc - A particular item.
File
- includes/
crud.inc, line 912 - CRUD functions for backup and migrate types (schedules, profiles etc.).
Class
- backup_migrate_item
- A base class for items which can be stored in the database.
Code
public function all_items() {
$items = array();
// Get any items stored as a variable. This allows destinations to be
// defined in settings.php.
$defaults = (array) variable_get($this->db_table . '_defaults', array());
foreach ($defaults as $info) {
if (is_array($info) && ($item = $this
->create($info))) {
$items[$item
->get_id()] = $item;
}
}
// Get the items from the db.
$result = db_query("SELECT * FROM {{$this->db_table}}", array(), array(
'fetch' => PDO::FETCH_ASSOC,
));
foreach ($result as $info) {
$info = $this
->decode_db_row($info);
if ($item = $this
->create($info)) {
$item->storage = empty($items[$item
->get_id()]) ? BACKUP_MIGRATE_STORAGE_DB : BACKUP_MIGRATE_STORAGE_OVERRIDEN;
$items[$item
->get_id()] = $item;
}
}
// Allow other modules to declare destinations programatically.
$default_items = module_invoke_all($this->db_table);
// Get CTools exported versions.
if (function_exists('ctools_include')) {
ctools_include('export');
$defaults = ctools_export_load_object($this->db_table);
foreach ($defaults as $info) {
$info = (array) $info;
if (!empty($info) && ($item = $this
->create($info))) {
// If this item is not already in $default_items,
// set flag to indicate it's only there because of ctools export.
if (empty($default_items[$item
->get_id()])) {
$item->settings['ctools_export'] = TRUE;
}
$default_items[$item
->get_id()] = $item;
}
}
}
// Get any items stored as a variable again to correctly mark overrides.
$defaults = (array) variable_get($this->db_table . '_defaults', array());
foreach ($defaults as $info) {
if (is_array($info) && ($item = $this
->create($info))) {
$default_items[] = $item;
}
}
// Add the default items to the array or set the storage flag if they've
// already been overridden.
foreach ($default_items as $item) {
if (isset($items[$item
->get_id()])) {
// Items added by ctools export are not overrides.
if (empty($item->settings['ctools_export'])) {
$items[$item
->get_id()]->storage = BACKUP_MIGRATE_STORAGE_OVERRIDEN;
}
}
else {
$item->storage = BACKUP_MIGRATE_STORAGE_NONE;
$items[$item
->get_id()] = $item;
}
}
// Allow other modules to alter the items. This should maybe be before the
// db override code above but then the filters are not able to set defaults
// for missing values. Other modules should just be careful not to
// overwrite the user's UI changes in an unexpected way.
drupal_alter($this->db_table, $items);
return $items;
}