function _patterns_io_get_patterns in Patterns 7
Same name and namespace in other branches
- 7.2 includes/io/io.inc \_patterns_io_get_patterns()
Loads all the available patterns from the database. It also checks against the file system, and, if the patterns global configuration options allow it, updates the database with the latest modifications. Notice: enabled patterns will not be updated anyway.
Parameters
$reset if TRUE, it always updates the patterns in: the database with the file system.
bool $verbose If TRUE, only public patterns: are returned
bool $public If TRUE, verbose output is: printed to screen
Return value
array The array of available patterns.
2 calls to _patterns_io_get_patterns()
- patterns_io_get_patterns in includes/
io/ io.inc - Wrapper function for _patterns_io_get_patterns.
- patterns_io_get_public_patterns in includes/
io/ io.inc - Wrapper function for _patterns_io_get_patterns.
File
- includes/
io/ io.inc, line 248 - Functions related to input/output operations.
Code
function _patterns_io_get_patterns($reset = TRUE, $verbose = TRUE, $public = FALSE) {
if ($reset || !variable_get('patterns_loaded', FALSE)) {
// Updates the patterns in the database
patterns_io_scan_directories($verbose);
}
// Get all the patterns from the database
$result = patterns_db_get_patterns();
$messages = array();
$patterns = array();
$patterns[PATTERNS_STATUS_OK] = array();
$patterns[PATTERNS_STATUS_TRASHED] = array();
foreach ($result as $pattern) {
// Skip pattern if its name is missing.
if (!isset($pattern->name)) {
continue;
}
if ($public && !$pattern->public) {
continue;
}
// Skip pattern if its file is missing.
if (!is_file($pattern->file)) {
$messages[] = patterns_utils_toString($pattern);
}
$status = $pattern->status;
if (in_array($status, array(
PATTERNS_STATUS_OK,
PATTERNS_STATUS_ENABLED,
PATTERNS_STATUS_INVALID,
))) {
$status = PATTERNS_STATUS_OK;
}
else {
$status = PATTERNS_STATUS_TRASHED;
}
$patterns[$status][$pattern->pid] = $pattern;
$data = unserialize($pattern->pattern);
$patterns[$status][$pattern->pid]->pattern = $data;
$patterns[$status][$pattern->pid]->info = $data['info'];
}
if (!empty($messages)) {
drupal_set_message(t("The following patterns were found in the database, but not in the file system:") . '<br/>' . implode('<br/>', $messages) . '<br/>', 'warning');
}
return $patterns;
}