/** * @Then I should see a valid catalog xml */ public function iShouldSeeAValidCatalogXml() { // Change /catalog.xml path to /catalog during tests. The '.' on the filename breaks tests on CircleCI's server. $dcat = open_data_schema_map_api_load('dcat_v1_1'); if ($dcat->endpoint !== 'catalog') { $dcat->endpoint = 'catalog'; drupal_write_record('open_data_schema_map', $dcat, 'id'); drupal_static_reset('open_data_schema_map_api_load_all'); menu_rebuild(); } // Change /catalog.json path to /catalogjson during tests. The '.' on the filename breaks tests on CircleCI's server. $dcat_json = open_data_schema_map_api_load('dcat_v1_1_json'); if ($dcat_json->endpoint !== 'catalogjson') { $dcat_json->endpoint = 'catalogjson'; drupal_write_record('open_data_schema_map', $dcat_json, 'id'); drupal_static_reset('open_data_schema_map_api_load_all'); menu_rebuild(); } // Get base URL. $url = $this->getMinkParameter('base_url') ? $this->getMinkParameter('base_url') : "http://127.0.0.1::8888"; $url_xml = $url . '/catalog'; $url_json = $url . '/catalogjson'; $this->visitPath($url_xml); $this->assertSession()->statusCodeEquals('200'); // Validate DCAT. $results = open_data_schema_dcat_process_validate($url_json, TRUE); if ($results['errors']) { throw new \Exception(sprintf('catalog.xml is not valid.')); } }
/** * Overrides ctools_export_ui::edit_save_form(). * * Clear menu cache in case the SPARQL endpoint path was modified. */ function edit_save_form($form_state) { parent::edit_save_form($form_state); if (!empty($form_state['plugin']['schema']) && $form_state['plugin']['schema'] == 'arc2_store_settings') { menu_rebuild(); } }
/** * {@inheritDocs} */ public function match($pathinfo) { // The 'q' variable is pervasive in Drupal, so it's best to just keep // it even though it's very un-Symfony. $path = drupal_get_normal_path(substr($pathinfo, 1)); if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) { menu_rebuild(); } $original_map = arg(NULL, $path); $parts = array_slice($original_map, 0, MENU_MAX_PARTS); $ancestors = menu_get_ancestors($parts); $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); if ($router_item) { // Allow modules to alter the router item before it is translated and // checked for access. drupal_alter('menu_get_item', $router_item, $path, $original_map); // The requested path is an unalaised Drupal route. return array('_drupal' => true, '_controller' => function ($_router_item) { $router_item = $_router_item; if (!$router_item['access']) { throw new AccessDeniedException(); } if ($router_item['include_file']) { require_once DRUPAL_ROOT . '/' . $router_item['include_file']; } return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']); }, '_route' => $router_item['path']); } throw new ResourceNotFoundException(); }
/** * Asserts that we create a new search page and remove it again */ function testNewAndRemoveSearchPage() { // Create a new search page $this->drupalLogin($this->admin_user); $this->drupalGet('admin/config/search/apachesolr/search-pages'); $this->assertText(t('Add search page'), t('Create new search page link is available')); $this->clickLink(t('Add search page')); $this->assertText(t('The human-readable name of the search page configuration.'), t('Search page creation page succesfully added')); $edit = array('page_id' => 'solr_testingsuite', 'env_id' => 'solr', 'label' => 'Test Search Page', 'description' => 'Test Description', 'page_title' => 'Test Title', 'search_path' => 'search/searchdifferentpath'); $this->drupalPost($this->getUrl(), $edit, t('Save configuration')); $this->assertResponse(200); // Make sure the menu is recognized drupal_static_reset('apachesolr_search_page_load'); menu_cache_clear_all(); menu_rebuild(); $this->drupalGet('admin/config/search/apachesolr/search-pages'); $this->assertText(t('Test Search Page'), t('Search Page was succesfully created')); // Remove the same environment $this->clickLink(t('Delete')); $this->assertText(t('search page configuration will be deleted.This action cannot be undone.'), t('Delete confirmation page was succesfully loaded')); $this->drupalPost($this->getUrl(), array(), t('Delete page')); $this->assertResponse(200); drupal_static_reset('apachesolr_search_page_load'); $this->drupalGet('admin/config/search/apachesolr/search-pages'); $this->assertNoText(t('Test Search Page'), t('Search Environment was succesfully deleted')); }
/** * @param array $cache_types * The autoloader modes that are enabled, e.g. * array('apc' => 'apc', 'xcache' => 'xcache') * @param bool $cache_lazy * Whether the "lazy" mode is enabled. */ protected function xautoloadTestWithCacheTypes($cache_types, $cache_lazy) { // @FIXME // // @FIXME // // The correct configuration object could not be determined. You'll need to // // rewrite this call manually. // variable_set(XAUTOLOAD_VARNAME_CACHE_TYPES, $cache_types); $this->pass("Set cache types: " . var_export($cache_types, TRUE)); // @FIXME // // @FIXME // // The correct configuration object could not be determined. You'll need to // // rewrite this call manually. // variable_set(XAUTOLOAD_VARNAME_CACHE_LAZY, $cache_lazy); $this->pass("Set cache lazy mode: " . var_export($cache_lazy, TRUE)); // Enable xautoload. module_enable(array('xautoload'), FALSE); // At this time the xautoload_cache_mode setting is not in effect yet, // so we have to clear old cached values from APC cache. xautoload()->cacheManager->renewCachePrefix(); module_enable(array('xautoload_test_1', 'xautoload_test_2', 'xautoload_test_3', 'xautoload_test_4', 'xautoload_test_5'), FALSE); menu_rebuild(); foreach (array('xautoload_test_1' => array('Drupal\\xautoload_test_1\\ExampleClass'), 'xautoload_test_2' => array('xautoload_test_2_ExampleClass'), 'xautoload_test_3' => array('Drupal\\xautoload_test_3\\ExampleClass')) as $module => $classes) { $classes_on_include = in_array($module, array('xautoload_test_2', 'xautoload_test_3')); $this->xautoloadModuleEnabled($module, $classes, $classes_on_include); $this->xautoloadModuleCheckJson($module, $cache_types, $cache_lazy, $classes); } }
/** * Ensure menu gets rebuild after saving a new type. */ function edit_save_form($form_state) { parent::edit_save_form($form_state); entity_info_cache_clear(); menu_rebuild(); if ($form_state['op'] === 'save_continue') { $this->plugin['redirect']['save_continue'] = $this->field_admin_path($form_state['values']['name'], 'fields'); } }
/** * This hook called when a coupon type deleted. * * @param string $type Coupon type. */ function hook_commerce_coupon_type_delete($type) { // Delete all coupons of this type. if ($pids = array_keys(commerce_coupon_load_multiple(FALSE, array('type' => $type->type)))) { commerce_coupon_delete_multiple($pids); } // Rebuild the menu as any (user-category) menu items should be gone now. menu_rebuild(); }
public static function setUpBeforeClass() { // Change /data.json path to /json during tests. $data_json = open_data_schema_map_api_load('data_json_1_1'); $data_json->endpoint = 'json'; drupal_write_record('open_data_schema_map', $data_json, 'id'); drupal_static_reset('open_data_schema_map_api_load_all'); menu_rebuild(); }
function set_item_state($state, $js, $input, $item) { ctools_export_set_object_status($item, $state); menu_rebuild(); if (!$js) { drupal_goto(ctools_export_ui_plugin_base_path($this->plugin)); } else { return $this->list_page($js, $input); } }
/** * (non-PHPdoc) * @see Yamm_Entity::_update() */ protected function _update($object, $identifier) { // TODO we should check for all dependencies which are not data, such as // handlers and modules (this is done by views_export module). views_include('view'); // Should give us the '$view' variable eval($object); $view->save(); views_ui_cache_set($view); menu_rebuild(); cache_clear_all('*', 'cache_views'); cache_clear_all(); }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * * @param Application $app An Application instance */ public function register(Application $app) { $app['drupal.bootstrap.class'] = 'Bangpound\\Bridge\\Drupal\\Bootstrap'; $app['drupal.class'] = 'Druplex'; $app['legacy.request_matcher'] = $app->share($app->extend('legacy.request_matcher', function (RequestMatcher $matcher, $c) { $matcher->matchAttribute('_legacy', 'drupal'); return $matcher; })); $app['drupal.listener.header'] = $app->share(function ($c) { return new HeaderListener($c['legacy.request_matcher']); }); $app['drupal.bootstrap'] = $app->share(function () use($app) { /** @var Bootstrap $bootstrap */ $bootstrap = new $app['drupal.bootstrap.class'](); $bootstrap->setEventDispatcher($app['dispatcher']); require_once $app['web_dir'] . '/includes/bootstrap.inc'; drupal_bootstrap(NULL, TRUE, $bootstrap); return $bootstrap; }); $app->before(function (Request $request) use($app) { $app['drupal.bootstrap']; define('DRUPAL_ROOT', getcwd()); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $pathinfo = $request->getPathInfo(); // The 'q' variable is pervasive in Drupal, so it's best to just keep // it even though it's very un-Symfony. $path = drupal_get_normal_path(substr($pathinfo, 1)); if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) { menu_rebuild(); } $original_map = arg(NULL, $path); $parts = array_slice($original_map, 0, MENU_MAX_PARTS); $ancestors = menu_get_ancestors($parts); $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); if ($router_item) { // Allow modules to alter the router item before it is translated and // checked for access. drupal_alter('menu_get_item', $router_item, $path, $original_map); // The requested path is an unalaised Drupal route. $request->attributes->add(array('_route' => $router_item['path'], '_legacy' => 'drupal')); } }, 33); }
/** * @param array $cache_types * The autoloader modes that are enabled, e.g. * array('apc' => 'apc', 'xcache' => 'xcache') * @param bool $cache_lazy * Whether the "lazy" mode is enabled. */ protected function xautoloadTestWithCacheTypes($cache_types, $cache_lazy) { variable_set('xautoload_cache_types', $cache_types); $this->pass("Set cache types: " . var_export($cache_types, TRUE)); variable_set('xautoload_cache_lazy', $cache_lazy); $this->pass("Set cache lazy mode: " . var_export($cache_lazy, TRUE)); // Enable xautoload. module_enable(array('xautoload'), FALSE); // At this time the xautoload_cache_mode setting is not in effect yet, // so we have to clear old cached values from APC cache. xautoload()->cacheManager->renewCachePrefix(); module_enable(array('xautoload_test_1', 'xautoload_test_2', 'xautoload_test_3'), FALSE); menu_rebuild(); foreach (array('xautoload_test_1' => array('Drupal\\xautoload_test_1\\ExampleClass'), 'xautoload_test_2' => array('xautoload_test_2_ExampleClass'), 'xautoload_test_3' => array('Drupal\\xautoload_test_3\\ExampleClass')) as $module => $classes) { $classes_on_include = in_array($module, array('xautoload_test_2', 'xautoload_test_3')); $this->xautoloadModuleEnabled($module, $classes, $classes_on_include); $this->xautoloadModuleCheckJson($module, $cache_types, $cache_lazy, $classes); } }
/** * Installs Atrium instead of Drupal * * Generates a random database prefix, runs the install scripts on the * prefixed database and enable the specified modules. After installation * many caches are flushed and the internal browser is setup so that the * page requests will run on the new prefix. A temporary files directory * is created with the same name as the database prefix. * * @param ... * List of modules to enable for the duration of the test. */ protected function setUp() { global $db_prefix, $user, $language, $profile, $install_locale; // $language (Drupal 6). // Store necessary current values before switching to prefixed database. $this->originalPrefix = $db_prefix; $this->originalLanguage = clone $language; $clean_url_original = variable_get('clean_url', 0); // Must reset locale here, since schema calls t(). (Drupal 6) if (module_exists('locale')) { $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''); locale(NULL, NULL, TRUE); } // Generate temporary prefixed database to ensure that tests have a clean starting point. // $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); $install_locale = $this->install_locale; $profile = $this->install_profile; // include_once DRUPAL_ROOT . '/includes/install.inc'; include_once './includes/install.inc'; drupal_install_system(); // $this->preloadRegistry(); // Set up theme system for the maintenance page. // Otherwise we have trouble: https://ds.openatrium.com/dsi/node/18426#comment-38118 // @todo simpletest module patch drupal_maintenance_theme(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args)); $modules = array_unique(array_merge(drupal_verify_profile($this->install_profile, $this->install_locale), $args)); // drupal_install_modules($modules, TRUE); drupal_install_modules($modules); // Because the schema is static cached, we need to flush // it between each run. If we don't, then it will contain // stale data for the previous run's database prefix and all // calls to it will fail. drupal_get_schema(NULL, TRUE); if ($this->install_profile == 'openatrium') { // Download and import translation if needed if ($this->install_locale != 'en') { $this->installLanguage($this->install_locale); } // Install more modules $modules = _openatrium_atrium_modules(); drupal_install_modules($modules); // Configure intranet // $profile_tasks = $this->install_profile . '_profile_tasks'; _openatrium_intranet_configure(); _openatrium_intranet_configure_check(); variable_set('atrium_install', 1); // Clear views cache before rebuilding menu tree. Requires patch // [patch_here] to Views, as new modules have been included and // default views need to be re-detected. module_exists('views') ? views_get_all_views(TRUE) : TRUE; menu_rebuild(); } _drupal_flush_css_js(); $this->refreshVariables(); $this->checkPermissions(array(), TRUE); user_access(NULL, NULL, TRUE); // Drupal 6. // Log in with a clean $user. $this->originalUser = $user; // drupal_save_session(FALSE); // $user = user_load(1); session_save_session(FALSE); $user = user_load(array('uid' => 1)); // Restore necessary variables. variable_set('install_profile', $this->install_profile); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); variable_set('site_mail', '*****@*****.**'); // Use temporary files directory with the same prefix as database. $this->originalFileDirectory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); $directory = file_directory_path(); // Create the files directory. file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); set_time_limit($this->timeLimit); }
function covidien_contenttype_update($arg) { module_load_include('inc', 'content', 'includes/content.crud'); $module_name = $arg['module_name']; $import_new = $arg['import_new']; $import_updatearr = $arg['import_updatearr']; $import_deletearr = $arg['import_deletearr']; $import_ctdeletearr = $arg['import_ctdeletearr']; $import_update = array_keys($import_updatearr); $files = file_scan_directory(drupal_get_path('module', $module_name) . '/content_type', '.cck_import.inc'); if (is_array($import_ctdeletearr) && count($import_ctdeletearr) > 0) { foreach ($import_ctdeletearr as $key => $fields) { if (count($fields) > 0) { foreach ($fields as $field_name) { $field = array(); $field['field_name'] = $field_name; $field['type_name'] = $key; content_field_instance_delete($field['field_name'], $field['type_name'], FALSE); drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']); } } } // Clear caches and rebuild menu. content_clear_type_cache(TRUE); menu_rebuild(); } foreach ($files as $absolute => $file) { // Creating new content type. if (in_array($file->name, $import_new)) { $form_state = array(); $form_state['values']['type_name'] = '<create>'; $fh = fopen($file->filename, 'r'); $theData = fread($fh, filesize($file->filename)); fclose($fh); $form_state['values']['macro'] = "$theData"; drupal_execute('content_copy_import_form', $form_state); } // Updating existing content type. if (in_array($file->name, $import_update)) { // Add the new fileds to the content type $form_state = array(); $form_state['values']['type_name'] = $import_updatearr[$file->name]; $fh = fopen($file->filename, 'r'); $theData = fread($fh, filesize($file->filename)); eval($theData); fclose($fh); $form_state['values']['macro'] = "$theData"; drupal_execute('content_copy_import_form', $form_state); // Update Title filed label $title_label = $content['type']['title_label']; $type = $content['type']['type']; db_query("UPDATE {node_type} SET title_label = '%s' WHERE type = '%s'", $title_label, $type); // Update several fields at a time. if (count($content['fields']) > 0) { foreach ($content['fields'] as $key => $field) { if (is_array($field)) { $field['type_name'] = $content['type']['type']; if ($field['type_name'] != '' && $field['field_name'] != '') { content_field_instance_update($field, FALSE); drupal_set_message('updated ' . $field['field_name'] . ' in ' . $field['type_name']); } } } } /** * Code to remove the cck filed from content type. */ if (is_array($import_deletearr)) { $fields = $import_deletearr[$file->name]; } if (count($fields) > 0) { foreach ($fields as $field_name) { $field = array(); $field['field_name'] = $field_name; $field['type_name'] = $import_updatearr[$file->name]; content_field_instance_delete($field['field_name'], $field['type_name'], FALSE); drupal_set_message('Deleted ' . $field['field_name'] . ' in ' . $field['type_name']); } } // Clear caches and rebuild menu. content_clear_type_cache(TRUE); menu_rebuild(); } } }
/** * Make uf join entries for an uf group. * * @param array $params * (reference) an assoc array of name/value pairs. * @param int $ufGroupId * Ufgroup id. */ public static function createUFJoin(&$params, $ufGroupId) { $groupTypes = CRM_Utils_Array::value('uf_group_type', $params); // get ufjoin records for uf group $ufGroupRecord = CRM_Core_BAO_UFGroup::getUFJoinRecord($ufGroupId); // get the list of all ufgroup types $allUFGroupType = CRM_Core_SelectValues::ufGroupTypes(); // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($groupTypes)) { $groupTypes = array(); } // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input if (!is_array($ufGroupRecord)) { $ufGroupRecord = array(); } // check which values has to be inserted/deleted for contact $menuRebuild = FALSE; foreach ($allUFGroupType as $key => $value) { $joinParams = array(); $joinParams['uf_group_id'] = $ufGroupId; $joinParams['module'] = $key; if ($key == 'User Account') { $menuRebuild = TRUE; } if (array_key_exists($key, $groupTypes) && !in_array($key, $ufGroupRecord)) { // insert a new record CRM_Core_BAO_UFGroup::addUFJoin($joinParams); } elseif (!array_key_exists($key, $groupTypes) && in_array($key, $ufGroupRecord)) { // delete a record for existing ufgroup CRM_Core_BAO_UFGroup::delUFJoin($joinParams); } } //update the weight $query = "\nUPDATE civicrm_uf_join\nSET weight = %1\nWHERE uf_group_id = %2\nAND ( entity_id IS NULL OR entity_id <= 0 )\n"; $p = array(1 => array($params['weight'], 'Integer'), 2 => array($ufGroupId, 'Integer')); CRM_Core_DAO::executeQuery($query, $p); // do a menu rebuild if we are on drupal, so it gets all the new menu entries // for user account $config = CRM_Core_Config::singleton(); if ($menuRebuild && $config->userSystem->is_drupal) { menu_rebuild(); } }
/** * tearDown implementation, setting back switched modules etc */ function tearDown() { foreach ($this->_cleanupModules as $name => $status) { db_query("UPDATE {system} SET status = %d WHERE name = '%s' AND type = 'module'", $status, $name); } $this->_cleanupModules = array(); // Refresh the modules list module_list(TRUE, FALSE); menu_rebuild(); foreach ($this->_cleanupVariables as $name => $value) { if (is_null($value)) { variable_del($name); } else { variable_set($name, $value); } } $this->_cleanupVariables = array(); while (sizeof($this->_cleanupRoles) > 0) { $rid = array_pop($this->_cleanupRoles); db_query("DELETE FROM {role} WHERE rid = %d", $rid); db_query("DELETE FROM {permission} WHERE rid = %d", $rid); } while (sizeof($this->_cleanupUsers) > 0) { $uid = array_pop($this->_cleanupUsers); // cleanup nodes this user created $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid); while ($node = db_fetch_array($result)) { node_delete($node['nid']); } user_delete(array(), $uid); } parent::tearDown(); }
/** * Generates a random database prefix and runs the install scripts on the prefixed database. * After installation many caches are flushed and the internal browser is setup so that the page * requests will run on the new prefix. A temporary files directory is created with the same name * as the database prefix. * * @param ... List modules to enable. */ function setUp() { global $db_prefix, $simpletest_ua_key; if ($simpletest_ua_key) { $this->db_prefix_original = $db_prefix; $clean_url_original = variable_get('clean_url', 0); $db_prefix = 'simpletest' . mt_rand(1000, 1000000); include_once './includes/install.inc'; drupal_install_system(); $modules = array_unique(array_merge(func_get_args(), drupal_verify_profile('default', 'en'))); drupal_install_modules($modules); $this->_modules = drupal_map_assoc($modules); $this->_modules['system'] = 'system'; $task = 'profile'; default_profile_tasks($task, ''); menu_rebuild(); actions_synchronize(); _drupal_flush_css_js(); variable_set('install_profile', 'default'); variable_set('install_task', 'profile-finished'); variable_set('clean_url', $clean_url_original); // Use temporary files directory with the same prefix as database. $this->original_file_directory = file_directory_path(); variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix); file_check_directory(file_directory_path(), TRUE); // Create the files directory. } parent::setUp(); }
/** * Installation task; perform final steps and display a 'finished' page. * * @param $install_state * An array of information about the current installation state. * @return * A message informing the user that the installation is complete. */ function install_finished(&$install_state) { drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name()))); $messages = drupal_set_message(); $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>'; $output .= '<p>' . (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>'; if (module_exists('help')) { $output .= '<p>' . st('For more information on configuring Drupal, please refer to the <a href="@help">help section</a>.', array('@help' => url('admin/help'))) . '</p>'; } // Rebuild menu and registry to get content type links registered by the // profile, and possibly any other menu items created through the tasks. menu_rebuild(); // Register actions declared by any modules. actions_synchronize(); // Randomize query-strings on css/js files, to hide the fact that this is a // new install, not upgraded yet. _drupal_flush_css_js(); // Remember the profile which was used. variable_set('install_profile', $install_state['parameters']['profile']); // Cache a fully-built schema. drupal_get_schema(NULL, TRUE); // Run cron to populate update status tables (if available) so that users // will be warned if they've installed an out of date Drupal version. // Will also trigger indexing of profile-supplied content or feeds. drupal_cron_run(); return $output; }
/** * tearDown implementation, setting back switched modules etc */ function tearDown() { if ($this->_modules != $this->_originalModules) { $form_state['values'] = array('status' => $this->_originalModules, 'op' => t('Save configuration')); drupal_execute('system_modules', $form_state); //rebuilding all caches drupal_rebuild_theme_registry(); node_types_rebuild(); menu_rebuild(); cache_clear_all('schema', 'cache'); module_rebuild_cache(); $this->_modules = $this->_originalModules; } foreach ($this->_cleanupVariables as $name => $value) { if (is_null($value)) { variable_del($name); } else { variable_set($name, $value); } } $this->_cleanupVariables = array(); //delete nodes foreach ($this->_cleanupNodes as $nid) { node_delete($nid); } $this->_cleanupNodes = array(); //delete roles while (sizeof($this->_cleanupRoles) > 0) { $rid = array_pop($this->_cleanupRoles); db_query("DELETE FROM {role} WHERE rid = %d", $rid); db_query("DELETE FROM {permission} WHERE rid = %d", $rid); } //delete users and their content while (sizeof($this->_cleanupUsers) > 0) { $uid = array_pop($this->_cleanupUsers); // cleanup nodes this user created $result = db_query("SELECT nid FROM {node} WHERE uid = %d", $uid); while ($node = db_fetch_array($result)) { node_delete($node['nid']); } user_delete(array(), $uid); } //delete content types foreach ($this->_cleanupContentTypes as $type) { node_type_delete($type); } $this->_cleanupContentTypes = array(); //Output drupal warnings and messages into assert messages $drupal_msgs = drupal_get_messages(); foreach ($drupal_msgs as $type => $msgs) { foreach ($msgs as $msg) { $this->assertTrue(TRUE, "{$type}: {$msg}"); } } parent::tearDown(); }
/** * Installation task; perform final steps and display a 'finished' page. * * @param $install_state * An array of information about the current installation state. * @return * A message informing the user that the installation is complete. */ function install_finished(&$install_state) { drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())), PASS_THROUGH); $messages = drupal_set_message(); $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>'; $output .= '<p>' . (isset($messages['error']) ? st('Review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>'; if (module_exists('help')) { $output .= '<p>' . st('For more information on configuring Drupal, refer to the <a href="@help">help section</a>.', array('@help' => url('admin/help'))) . '</p>'; } // Rebuild the module and theme data, in case any newly-installed modules // need to modify it via hook_system_info_alter(). We need to clear the // theme static cache first, to make sure that the theme data is actually // rebuilt. drupal_static_reset('_system_rebuild_theme_data'); system_rebuild_module_data(); system_rebuild_theme_data(); // Rebuild menu and registry to get content type links registered by the // profile, and possibly any other menu items created through the tasks. menu_rebuild(); // Rebuild the database cache of node types, so that any node types added // by newly installed modules are registered correctly and initialized with // the necessary fields. node_types_rebuild(); // Register actions declared by any modules. actions_synchronize(); // Randomize query-strings on css/js files, to hide the fact that this is a // new install, not upgraded yet. _drupal_flush_css_js(); // Remember the profile which was used. variable_set('install_profile', drupal_get_profile()); // Install profiles are always loaded last db_update('system')->fields(array('weight' => 1000))->condition('type', 'module')->condition('name', drupal_get_profile())->execute(); // Cache a fully-built schema. drupal_get_schema(NULL, TRUE); // Run cron to populate update status tables (if available) so that users // will be warned if they've installed an out of date Drupal version. // Will also trigger indexing of profile-supplied content or feeds. drupal_cron_run(); return $output; }
/** * Get Account Status * NOTE: You shouldnt need to call this directly. Its called in the constructor. * Request: https://LINGOTEK_BILLING_SERVER/billing/account.json?community=B2MMD3X5&external_id=community_admin&oauth_key=28c279fa-28dc-452e-93af-68d194a2c366&oauth_secret=0e999486-3b4d-47e4-ba9a-d0f3f0bbda73 * Response: {"state":"active","plan":{"trial_ends_at":0,"state":"active","activated_at":1355267936,"type":"cosmopolitan_monthly","languages_allowed":2,"language_cost_per_period_in_cents":14900}} * Will return FALSE or a json decoded object. */ function getAccountStatus() { $result = FALSE; $parameters = array('community' => variable_get('lingotek_community_identifier', ''), 'external_id' => variable_get('lingotek_login_id', ''), 'oauth_key' => variable_get('lingotek_oauth_consumer_id', ''), 'oauth_secret' => variable_get('lingotek_oauth_consumer_secret', '')); if (!empty($parameters['community']) && !empty($parameters['external_id']) && !empty($parameters['oauth_key']) && !empty($parameters['oauth_secret'])) { $timer_name = 'GET -' . microtime(TRUE); timer_start($timer_name); $api_url = LINGOTEK_BILLING_SERVER; $ch = curl_init($api_url . '?' . http_build_query($parameters)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //curl_setopt( $ch, CURLINFO_HEADER_OUT, TRUE ); $response = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $response_json = json_decode($response); //debug( $response ); //debug( $info ); $timer_results = timer_stop($timer_name); $message_params = array('@url' => $api_url, '@method' => 'GET account (billing API)', '!params' => $parameters, '!response' => $response_json, '@response_time' => number_format($timer_results['time']) . ' ms'); if (isset($response_json) && $info['http_code'] == 200) { // Did we get valid json data back? If not, $json is NULL. //debug ( $json ); LingotekLog::info('<h1>@method</h1> <strong>API URL:</strong> @url <br /><strong>Response Time:</strong> @response_time<br /><strong>Request Params</strong>: !params<br /><strong>Response:</strong> !response', $message_params, 'api'); $response_data = $response; $result = TRUE; // Not Found - {"state":"not_found"} - Account isn't setup yet. The state after autoprovisioning a community, but before setting up your billing account. if ($response_json->state == self::NOT_FOUND) { $this->setStatus(self::NOT_FOUND); $this->setPlan(self::NONE); } elseif ($response_json->state == self::ACTIVE) { $this->setStatus(self::ACTIVE); variable_set('lingotek_account_status', self::ACTIVE); if (is_object($response_json->plan)) { $this->setPlan($response_json->plan); } // END: Plan menu_rebuild(); } // END Active } else { LingotekLog::error('<h1>@method (Failed)</h1> <strong>API URL:</strong> @url <br /><strong>Response Time:</strong> @response_time<br /><strong>Request Params</strong>: !params<br /><strong>Response:</strong> !response<br/><strong>Full Request:</strong> !request', $message_params, 'api'); } } // END: has credentials return $result; }
/** * Tasks performed after the database is initialized. */ function install_tasks($profile, $task) { global $base_url, $install_locale; // Bootstrap newly installed Drupal, while preserving existing messages. $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : ''; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $_SESSION['messages'] = $messages; // URL used to direct page requests. $url = $base_url . '/install.php?locale=' . $install_locale . '&profile=' . $profile; // Build a page for final tasks. if (empty($task)) { variable_set('install_task', 'profile-install'); $task = 'profile-install'; } // We are using a list of if constructs here to allow for // passing from one task to the other in the same request. // Install profile modules. if ($task == 'profile-install') { $modules = variable_get('install_profile_modules', array()); $files = module_rebuild_cache(); variable_del('install_profile_modules'); $operations = array(); foreach ($modules as $module) { $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name'])); } $batch = array('operations' => $operations, 'finished' => '_install_profile_batch_finished', 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())), 'error_message' => st('The installation has encountered an error.')); // Start a batch, switch to 'profile-install-batch' task. We need to // set the variable here, because batch_process() redirects. variable_set('install_task', 'profile-install-batch'); batch_set($batch); batch_process($url, $url); } // We are running a batch install of the profile's modules. // This might run in multiple HTTP requests, constantly redirecting // to the same address, until the batch finished callback is invoked // and the task advances to 'locale-initial-import'. if ($task == 'profile-install-batch') { include_once 'includes/batch.inc'; $output = _batch_page(); } // Import interface translations for the enabled modules. if ($task == 'locale-initial-import') { if (!empty($install_locale) && $install_locale != 'en') { include_once 'includes/locale.inc'; // Enable installation language as default site language. locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE); // Collect files to import for this language. $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished'); if (!empty($batch)) { // Remember components we cover in this batch set. variable_set('install_locale_batch_components', $batch['#components']); // Start a batch, switch to 'locale-batch' task. We need to // set the variable here, because batch_process() redirects. variable_set('install_task', 'locale-initial-batch'); batch_set($batch); batch_process($url, $url); } } // Found nothing to import or not foreign language, go to next task. $task = 'configure'; } if ($task == 'locale-initial-batch') { include_once 'includes/batch.inc'; include_once 'includes/locale.inc'; $output = _batch_page(); } if ($task == 'configure') { if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) { // Site already configured: This should never happen, means re-running // the installer, possibly by an attacker after the 'install_task' variable // got accidentally blown somewhere. Stop it now. install_already_done_error(); } $form = drupal_get_form('install_configure_form', $url); if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) { // Not submitted yet: Prepare to display the form. $output = $form; drupal_set_title(st('Configure site')); // Warn about settings.php permissions risk $settings_dir = './' . conf_path(); $settings_file = $settings_dir . '/settings.php'; if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) { drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, please consult the <a href="@handbook_url">on-line handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/getting-started')), 'error'); } else { drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file))); } // Add JavaScript validation. _user_password_dynamic_validation(); drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module'); // We add these strings as settings because JavaScript translation does not // work on install time. drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')), 'cleanURL' => array('success' => st('Your server has been successfully tested to support this feature.'), 'failure' => st('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => st('Testing clean URLs...'))), 'setting'); drupal_add_js(' // Global Killswitch if (Drupal.jsEnabled) { $(document).ready(function() { Drupal.cleanURLsInstallCheck(); Drupal.setDefaultTimezone(); }); }', 'inline'); // Build menu to allow clean URL check. menu_rebuild(); } else { $task = 'profile'; } } // If found an unknown task or the 'profile' task, which is // reserved for profiles, hand over the control to the profile, // so it can run any number of custom tasks it defines. if (!in_array($task, install_reserved_tasks())) { $function = $profile . '_profile_tasks'; if (function_exists($function)) { // The profile needs to run more code, maybe even more tasks. // $task is sent through as a reference and may be changed! $output = $function($task, $url); } // If the profile doesn't move on to a new task we assume // that it is done. if ($task == 'profile') { $task = 'profile-finished'; } } // Profile custom tasks are done, so let the installer regain // control and proceed with importing the remaining translations. if ($task == 'profile-finished') { if (!empty($install_locale) && $install_locale != 'en') { include_once 'includes/locale.inc'; // Collect files to import for this language. Skip components // already covered in the initial batch set. $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array())); // Remove temporary variable. variable_del('install_locale_batch_components'); if (!empty($batch)) { // Start a batch, switch to 'locale-remaining-batch' task. We need to // set the variable here, because batch_process() redirects. variable_set('install_task', 'locale-remaining-batch'); batch_set($batch); batch_process($url, $url); } } // Found nothing to import or not foreign language, go to next task. $task = 'finished'; } if ($task == 'locale-remaining-batch') { include_once 'includes/batch.inc'; include_once 'includes/locale.inc'; $output = _batch_page(); } // Display a 'finished' page to user. if ($task == 'finished') { drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name()))); $messages = drupal_set_message(); $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>'; $output .= '<p>' . (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>'; $task = 'done'; } // The end of the install process. Remember profile used. if ($task == 'done') { // Rebuild menu to get content type links registered by the profile, // and possibly any other menu items created through the tasks. menu_rebuild(); // Register actions declared by any modules. actions_synchronize(); // Randomize query-strings on css/js files, to hide the fact that // this is a new install, not upgraded yet. _drupal_flush_css_js(); variable_set('install_profile', $profile); } // Set task for user, and remember the task in the database. install_task_list($task); variable_set('install_task', $task); // Output page, if some output was required. Otherwise it is possible // that we are printing a JSON page and theme output should not be there. if (isset($output)) { print theme('maintenance_page', $output); } }
/** * lms_create_content_type create content type by given information. * * @param mixed $content_type_machine_name * @param mixed $content_type_display_name * @param mixed $content_type_desc * @return void */ function lms_create_content_type($content_type_machine_name, $content_type_display_name, $content_type_desc, $og_type = 'group_post_standard') { // 0. delete the existing type with the same name if exists node_type_delete($content_type_machine_name); // 1. Create content type firstly. $node_type = array( 'type' => $content_type_machine_name, 'name' => $content_type_display_name, 'module' => 'node', 'description' => $content_type_desc, 'custom' => TRUE, 'modified' => TRUE, 'locked' => FALSE, ); $node_type = (object)_node_type_set_defaults($node_type); node_type_save($node_type); // // 2. Add fileds to the content type // $instance = array( // 'field_name' => 'lms_node_type', // 'entity_type' => 'node', // 'bundle' => $content_type_machine_name, // 'label' => t('lms node name'), // 'description' => t('indicator of the node type'), // 'widget' => array( // 'type' => 'text_textfield', // 'weight' => 10, // ), // ); // field_create_instance($instance); node_types_rebuild(); menu_rebuild(); // set og type if ($og_type && $og_type != 'ommitted') { lms_set_content_type_as_og_group_post($content_type_machine_name, $og_type); } }
function brukar_client_admin_submit($form, &$form_state) { menu_rebuild(); }
function updateCategories() { // copied this from profile.module. Seems a bit inefficient, but i dont know a better way // CRM-3600 cache_clear_all(); menu_rebuild(); }
<?php error_reporting(E_ALL); define('DRUPAL_ROOT', getcwd()); require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); menu_rebuild();
/** * Creates a custom content type based on default settings. * * @param $settings * An array of settings to change from the defaults. * Example: 'type' => 'foo'. * @return * Created content type. */ protected function backdropCreateContentType($settings = array()) { // Find a non-existent random type name. do { $name = strtolower($this->randomName(8)); } while (node_type_get_type($name)); // Populate defaults array. $defaults = array('type' => $name, 'name' => $name, 'base' => 'node_content', 'description' => '', 'help' => '', 'title_label' => 'Title', 'body_label' => 'Body', 'has_title' => 1, 'has_body' => 1, 'is_new' => TRUE); // Imposed values for a custom type. $forced = array('orig_type' => '', 'old_type' => '', 'module' => 'node', 'custom' => 1, 'modified' => 1, 'locked' => 0); $type = $forced + $settings + $defaults; $type = (object) $type; $saved_type = node_type_save($type); menu_rebuild(); node_add_body_field($type); $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type))); // Reset permissions so that permissions for this content type are available. $this->checkPermissions(array(), TRUE); return $type; }
/** * Submit function for settings form. * Pack values into an array, process update and rebuild menu if needed. */ function _groupadmin_settings_form_submit($form, &$form_state) { //drupal_set_message(print_r($form_state, 1), 'error'); //drupal_set_message(print_r($form, 1), 'warning'); //drupal_set_message(print_r($form['f_access_control'], 1), 'warning'); // Reference form_state['values'] for use later. $values =& $form_state['values']; // Get current config (used to test if menu rebuild is needed.) $old_config = variable_get('groupadmin', array()); // We could skip these steps if "Reset to defaults" was selected, but we do them anyway. if (TRUE) { // Get config $fields. $fields = _groupadmin_settings_fields(); // Copy relevant $values into $new_state. $new_state['values']['op'] = $values['op']; $new_state['values']['groupadmin'] = array_intersect_key($values, $fields); } // Process via systems_settings_form_submit() so that Drupal standard messages are displayed. // @todo: Consider if really worth using system_settings_form. system_settings_form_submit($form, $new_state); // Reload new config from newly saved version ("Reset to defaults" may have been used.) $new_config = variable_get('groupadmin', array()); // Check if menu needs to be rebuilt... $changes = array_diff_assoc($new_config, $old_config); foreach ($changes as $key => $value) { if ($fields[$key][3]) { menu_rebuild(); drupal_set_message('The menu has been rebuilt.'); break; } } }
/** * Registry Rebuild needs to aggressively clear all caches, * not just some bins (at least to attempt it) also *before* * attempting to rebuild registry, or it may not be able * to fix the problem at all, if it relies on some cached * and no longer valid data/paths etc. This problem has been * confirmed and reproduced many times with option --fire-bazooka * which is available only in the Drush variant, but it confirms * the importance of starting with real, raw and not cached * in any way site state. While the --no-cache-clear option * still disables this procedure, --fire-bazooka takes precedence * and forces all caches clear action. All caches are cleared * by default in the PHP script variant. */ function registry_rebuild_cc_all() { if (function_exists('cache_clear_all')) { cache_clear_all('*', 'cache', TRUE); cache_clear_all('*', 'cache_form', TRUE); } else { cache('cache')->deleteAll(); cache('cache_form')->deleteAll(); } if (function_exists('module_rebuild_cache')) { // D5-D6 module_list(TRUE, FALSE); module_rebuild_cache(); } if (function_exists('drupal_flush_all_caches')) { // D6+ drupal_flush_all_caches(); } else { // D5 cache_clear_all(); system_theme_data(); node_types_rebuild(); menu_rebuild(); } print "All caches have been cleared with registry_rebuild_cc_all.<br/>\n"; }
/** * Installation task; configure settings for the new site. * * @param $form_state * An associative array containing the current state of the form. * @param $install_state * An array of information about the current installation state. * @return * The form API definition for the site configuration form. */ function install_configure_form($form, &$form_state, &$install_state) { if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) { // Site already configured: This should never happen, means re-running the // installer, possibly by an attacker after the 'install_task' variable got // accidentally blown somewhere. Stop it now. throw new Exception(install_already_done_error()); } drupal_set_title(st('Configure site')); // Warn about settings.php permissions risk $settings_dir = './' . conf_path(); $settings_file = $settings_dir . '/settings.php'; if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) { drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); } else { drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file))); } drupal_add_js(drupal_get_path('module', 'system') . '/system.js'); // Add JavaScript time zone detection. drupal_add_js('misc/timezone.js'); // We add these strings as settings because JavaScript translation does not // work on install time. drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail'))), 'setting'); drupal_add_js('jQuery(function () { Drupal.cleanURLsInstallCheck(); });', 'inline'); // Add JS to show / hide the 'Email administrator about site updates' elements drupal_add_js('jQuery(function () { Drupal.hideEmailAdministratorCheckbox() });', 'inline'); // Build menu to allow clean URL check. menu_rebuild(); // Cache a fully-built schema. This is necessary for any invocation of // index.php because: (1) setting cache table entries requires schema // information, (2) that occurs during bootstrap before any module are // loaded, so (3) if there is no cached schema, drupal_get_schema() will // try to generate one but with no loaded modules will return nothing. // // This logically could be done during the 'install_finished' task, but the // clean URL check requires it now. drupal_get_schema(NULL, TRUE); // Return the form. return _install_configure_form($form, $form_state, $install_state); }