/** * Respond to a custom menu deletion. * * This hook is used to notify modules that a custom menu along with all links * contained in it (if any) has been deleted. Contributed modules may use the * information to perform actions based on the information entered into the menu * system. * * @param $menu * An array representing a custom menu: * - menu_name: The unique name of the custom menu. * - title: The human readable menu title. * - description: The custom menu description. * * @see hook_menu_insert() * @see hook_menu_update() */ function hook_menu_delete($menu) { // Delete the record from our state setting. $my_menus = state_get('my_module_menus', array()); unset($my_menus[$menu['menu_name']]); state_set('my_module_menus', $my_menus); }
/** * Sets up a Backdrop site for running functional and integration tests. * * Generates a random database prefix and installs Backdrop with the specified * installation profile in BackdropWebTestCase::$profile into the * prefixed database. Afterwards, installs any additional modules specified by * the test. * * After installation all caches are flushed and several configuration values * are reset to the values of the parent site executing the test, since the * default values may be incompatible with the environment in which tests are * being executed. * * @param ... * List of modules to enable for the duration of the test. This can be * either a single array or a variable number of string arguments. * * @see BackdropWebTestCase::prepareDatabasePrefix() * @see BackdropWebTestCase::changeDatabasePrefix() * @see BackdropWebTestCase::prepareEnvironment() */ protected function setUp() { global $user, $language, $conf; // Create the database prefix for this test. $this->prepareDatabasePrefix(); // Prepare the environment for running tests. $this->prepareEnvironment(); if (!$this->setupEnvironment) { return FALSE; } // Reset all statics and variables to perform tests in a clean environment. $conf = array(); backdrop_static_reset(); // Change the database prefix. // All static variables need to be reset before the database prefix is // changed, since BackdropCacheArray implementations attempt to // write back to persistent caches when they are destructed. $this->changeDatabasePrefix(); if (!$this->setupDatabasePrefix) { return FALSE; } // Preset the 'install_profile' system variable, so the first call into // system_rebuild_module_data() (in backdrop_install_system()) will register // the test's profile as a module. Without this, the installation profile of // the parent site (executing the test) is registered, and the test // profile's hook_install() and other hook implementations are never invoked. config_install_default_config('system'); config_set('system.core', 'install_profile', $this->profile); // Perform the actual Backdrop installation. include_once BACKDROP_ROOT . '/core/includes/install.inc'; backdrop_install_system(); // Set path variables. $core_config = config('system.core'); $core_config->set('file_default_scheme', 'public'); $core_config->set('file_public_path', $this->public_files_directory); $core_config->set('file_private_path', $this->private_files_directory); $core_config->set('file_temporary_path', $this->temp_files_directory); $core_config->save(); // Set 'parent_profile' of simpletest to add the parent profile's // search path to the child site's search paths. // @see backdrop_system_listing() // @todo This may need to be primed like 'install_profile' above. config_set('simpletest.settings', 'parent_profile', $this->originalProfile); // Ensure schema versions are recalculated. backdrop_static_reset('backdrop_get_schema_versions'); // Include the testing profile. config_set('system.core', 'install_profile', $this->profile); $profile_details = install_profile_info($this->profile, 'en'); // Install the modules specified by the testing profile. module_enable($profile_details['dependencies'], FALSE); // Install modules needed for this test. This could have been passed in as // either a single array argument or a variable number of string arguments. // @todo Remove this compatibility layer and only accept a single array. $modules = func_get_args(); if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } if ($modules) { $success = module_enable($modules, TRUE); $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); } // Run the profile tasks. $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(':name' => $this->profile))->fetchField(); if ($install_profile_module_exists) { module_enable(array($this->profile), FALSE); } // Reset/rebuild all data structures after enabling the modules. $this->resetAll(); // Run cron once in that environment, as install.php does at the end of // the installation process. backdrop_cron_run(); // Ensure that the session is not written to the new environment and replace // the global $user session with uid 1 from the new test site. backdrop_save_session(FALSE); // Login as uid 1. $user = user_load(1); // Restore necessary variables. state_set('install_task', 'done'); config_set('system.core', 'clean_url', $this->originalCleanUrl); config_set('system.core', 'site_mail', '*****@*****.**'); config_set('system.date', 'date_default_timezone', date_default_timezone_get()); backdrop_static_reset('url'); // Set up English language. unset($conf['language_default']); $language = language_default(); // Use the test mail class instead of the default mail handler class. config_set('system.mail', 'default-system', 'TestingMailSystem'); backdrop_set_time_limit($this->timeLimit); $this->setup = TRUE; }
/** * Act on field_attach_create_bundle(). * * This hook is invoked after the field module has performed the operation. * * See field_attach_create_bundle() for details and arguments. */ function hook_field_attach_create_bundle($entity_type, $bundle) { // When a new bundle is created, the menu needs to be rebuilt to add the // Field UI menu item tabs. state_set('menu_rebuild_needed', TRUE); }
// Figure out if it's been 24 hours since our last daily processing. if (state_get('project_usage_last_daily', 0) <= $now - PROJECT_USAGE_DAY) { project_usage_process_daily(); state_set('project_usage_last_daily', $now); } // We can't process the weekly data until the week has completed. To see if // there's data available: determine the last time we completed the weekly // processing and compare that to the start of this week. If the last // weekly processing occurred before the current week began then there should // be one (or more) week's worth of data ready to process. $default = $now - config_get('project_usage.settings', 'life_daily'); $last_weekly = state_get('project_usage_last_weekly', $default); $current_week_start = project_usage_weekly_timestamp(NULL, 0); if ($last_weekly <= $current_week_start) { project_usage_process_weekly($last_weekly); state_set('project_usage_last_weekly', $now); // Reset the list of active weeks. project_usage_get_active_weeks(TRUE); } // Wipe the cache of all expired usage pages. cache('project_usage')->flush(); /** * Process all the raw data up to the previous day. * * The primary key on the {project_usage_raw} table will prevent duplicate * records provided we process them once the day is complete. If we pull them * out too soon and the site checks in again they will be counted twice. */ function project_usage_process_daily() { // Timestamp for beginning of the previous day.
/** * Update the search index for this module. * * This hook is called every cron run if search.module is enabled, your * module has implemented hook_search_info(), and your module has been set as * an active search module on the Search settings page * (admin/config/search/settings). It allows your module to add items to the * built-in search index using search_index(), or to add them to your module's * own indexing mechanism. * * When implementing this hook, your module should index content items that * were modified or added since the last run. PHP has a time limit * for cron, though, so it is advisable to limit how many items you index * per run using config_get('search.settings', 'search_cron_limit') (see * example below). Also, since the cron run could time out and abort in the * middle of your run, you should update your module's internal bookkeeping on * when items have last been indexed as you go rather than waiting to the end * of indexing. * * @ingroup search */ function hook_update_index() { $limit = (int) config_get('search.settings', 'search_cron_limit'); $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit); foreach ($result as $node) { $node = node_load($node->nid); // Save the changed time of the most recent indexed node, for the search // results half-life calculation. state_set('node_cron_last', $node->changed); // Render the node. node_build_content($node, 'search_index'); $node->rendered = backdrop_render($node->content); $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered; // Fetch extra data normally not visible $extra = module_invoke_all('node_update_index', $node); foreach ($extra as $t) { $text .= $t; } // Update index search_index($node->nid, 'node', $text); } }
$tables_updated = TRUE; } // Process the weekly data up until the current week. Data for the current // (partial) week is not calculated. $last_processed_weekly_timestamp = state_get('project_usage_last_weekly', REQUEST_TIME - PROJECT_USAGE_YEAR); $start_of_current_week = project_usage_weekly_timestamp(); if ($last_processed_weekly_timestamp < $start_of_current_week) { // Start with the week following last processed one. $next_weekly_timestamp = project_usage_weekly_timestamp($last_processed_weekly_timestamp, 1); // Process all weeks up until the current one. while ($next_weekly_timestamp < $start_of_current_week) { // Increment the timestamp to the next week. $last_weekly_timestamp = $next_weekly_timestamp; $next_weekly_timestamp = project_usage_weekly_timestamp($last_weekly_timestamp, 1); project_usage_process_weekly($last_weekly_timestamp); state_set('project_usage_last_weekly', $last_weekly_timestamp); } // Reset the list of active weeks. project_usage_get_active_weeks(TRUE); $tables_updated = TRUE; } // Wipe the cache of all expired usage pages. if ($tables_updated) { project_usage_remove_expired_data(); cache('project_usage')->flush(); } // All done. exit; /** * Assign node IDs to all the raw data that has been written. */