function sess_write($key, $value) { global $perfil, $cfg; $mysql = new MYSQL($cfg); // If saving of session data is disabled or if the client doesn't have a session, // and one isn't being created ($value), do nothing. This keeps crawlers out of // the session table. This reduces memory and server load, and gives more useful // statistics. We can't eliminate anonymous session table rows without breaking // the throttle module and the "Who's Online" block. if (!session_save_session() || $perfil->ID_USER == 0 && empty($_COOKIE[session_name()]) && empty($value)) { return TRUE; } $mysql->SqlSelect("UPDATE {sessions} SET ID_USER = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE ID_SESSION = '%s'", $perfil->ID_USER, isset($perfil->cache) ? $perfil->cache : '', ip_address(), $value, time(), $key); if (mysql_affected_rows()) { // Last access time is updated no more frequently than once every 180 seconds. // This reduces contention in the users table. if ($perfil->ID_USER && time() - $perfil->access > variable_get('session_write_interval', 180)) { $mysql->SqlSelect("UPDATE {users} SET access = %d WHERE ID_USER = %d", time(), $perfil->ID_USER); } } else { // If this query fails, another parallel request probably got here first. // In that case, any session data generated in this request is discarded. @$mysql->SqlSelect("INSERT INTO {sessions} (ID_SESSION, ID_USER, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $perfil->ID_USER, isset($perfil->cache) ? $perfil->cache : '', ip_address(), $value, time()); } return TRUE; }
function os_poker_poll_messages() { //Disable session writing, //see http://drupal-dev.pokersource.info/trac/ticket/37 session_save_session(FALSE); $GLOBALS['conf']['cache'] = CACHE_DISABLED; if (function_exists('set_time_limit')) { //script execution time fixed to 2mn @set_time_limit(120); } $current_user = CUserManager::instance()->CurrentUser(); $resp = array("errorMsg" => NULL, "error" => FALSE, "messages" => array()); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); if ($current_user && $current_user->uid != 0) { //process takes only 1mn to avoid js / php timeout for ($pass = 0; $pass < 20; ++$pass) { if (CScheduler::instance()->IsNewTask()) { CScheduler::instance()->ReloadTasks(); CScheduler::instance()->Trigger("inbox"); $mbox = CScheduler::instance()->GetUnreadTasks("inbox"); $mboxsize = count($mbox); $resp["messages"][] = array("type" => "os_poker_messagebox", "body" => array("inbox" => $mboxsize, "picture" => $base_path . drupal_get_path('module', 'os_poker') . "/images/mailbox.png")); } CScheduler::instance()->Trigger("live"); //Trigger live, and fill message spooler $messages = CMessageSpool::instance()->Get(); foreach ($messages as $msg) { $resp["messages"][] = $msg; } CMessageSpool::instance()->Flush(); if (count($resp["messages"]) > 0) { return json_encode($resp); } sleep(3); //poll every 3 sec } } else { sleep(60); } if (count($resp["messages"]) == 0) { $resp["messages"][] = array("type" => "noop", "body" => NULL); } return json_encode($resp); }
/** * 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); }
/** * Delete created files and temporary files directory, delete the tables created by setUp(), * and reset the database prefix. */ protected function tearDown() { global $db_prefix, $user, $language; // In case a fatal error occured that was not in the test process read the // log to pick up any fatal errors. $db_prefix_temp = $db_prefix; $db_prefix = $this->originalPrefix; simpletest_log_read($this->testId, $db_prefix, get_class($this), TRUE); $db_prefix = $db_prefix_temp; $emailCount = count(variable_get('drupal_test_email_collector', array())); if ($emailCount) { $message = format_plural($emailCount, t('!count e-mail was sent during this test.'), t('!count e-mails were sent during this test.'), array('!count' => $emailCount)); $this->pass($message, t('E-mail')); } if (preg_match('/simpletest\\d+/', $db_prefix)) { // Delete temporary files directory. // file_unmanaged_delete_recursive(file_directory_path()); simpletest_clean_temporary_directory(file_directory_path()); // Remove all prefixed tables (all the tables in the schema). $schema = drupal_get_schema(NULL, TRUE); $ret = array(); foreach ($schema as $name => $table) { db_drop_table($ret, $name); } // Return the database prefix to the original. $db_prefix = $this->originalPrefix; // Return the user to the original one. $user = $this->originalUser; // drupal_save_session(TRUE); session_save_session(TRUE); // Bring back default language. (Drupal 6) if (module_exists('locale')) { drupal_init_language(); locale(NULL, NULL, TRUE); } // Ensure that internal logged in variable and cURL options are reset. $this->loggedInUser = FALSE; $this->additionalCurlOptions = array(); // Reload module list and implementations to ensure that test module hooks // aren't called after tests. module_list(TRUE); // module_implements('', FALSE, TRUE); module_implements('', '', TRUE); // Reset the Field API. // field_cache_clear(); // Rebuild caches. $this->refreshVariables(); // // Reset language. // $language = $this->originalLanguage; // if ($this->originalLanguageDefault) { // $GLOBALS['conf']['language_default'] = $this->originalLanguageDefault; // } // Close the CURL handler. $this->curlClose(); } }
/** * Delete created files and temporary files directory, delete the tables created by setUp(), * and reset the database prefix. */ protected function tearDown() { global $db_prefix, $user; if (preg_match('/simpletest\\d+/', $db_prefix)) { // Delete temporary files directory and reset files directory path. // file_unmanaged_delete_recursive(file_directory_path()); simpletest_clean_temporary_directory(file_directory_path()); variable_set('file_directory_path', $this->originalFileDirectory); // Remove all prefixed tables (all the tables in the schema). $schema = drupal_get_schema(NULL, TRUE); $ret = array(); foreach ($schema as $name => $table) { db_drop_table($ret, $name); } // Return the database prefix to the original. $db_prefix = $this->originalPrefix; // Return the user to the original one. $user = $this->originalUser; // drupal_save_session(TRUE); session_save_session(TRUE); // Bring back default language. (Drupal 6) if (module_exists('locale')) { drupal_init_language(); locale(NULL, NULL, TRUE); } // Ensure that internal logged in variable and cURL options are reset. $this->loggedInUser = FALSE; $this->additionalCurlOptions = array(); // Reload module list and implementations to ensure that test module hooks // aren't called after tests. module_list(TRUE); // module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE); module_implements('', '', TRUE); // Reset the Field API. // field_cache_clear(); // Rebuild caches. $this->refreshVariables(); // Close the CURL handler. $this->curlClose(); } }
/** * 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. */ function setUp() { global $db_prefix, $user, $language; // $language (Drupal 6). global $install_locale; // Store necessary current values before switching to prefixed database. $this->db_prefix_original = $db_prefix; $clean_url_original = variable_get('clean_url', 0); // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); include_once './includes/install.inc'; drupal_install_system(); // Add the specified modules to the list of modules in the default profile. $args = func_get_args(); // Add language and basic i18n modules $install_locale = $this->install_locale; $i18n_modules = array('locale', 'translation', 'i18n', 'i18n_test'); $modules = array_unique(array_merge(drupal_verify_profile('default', $this->install_locale), $args, $i18n_modules)); drupal_install_modules($modules); // Install locale if ($this->install_locale != 'en') { $this->addLanguage($this->install_locale, TRUE); } // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); // Rebuild caches. actions_synchronize(); _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(1); // Restore necessary variables. variable_set('install_profile', 'default'); 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); drupal_set_time_limit($this->timeLimit); // Some more includes require_once 'includes/language.inc'; // Refresh theme $this->initTheme(); // Set path languages so we can retrieve pages in different languages variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH); }
$files = files_list($argv); // ############################################################################# // Primary Loop // ############################################################################# for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; $head = ''; $body = ''; $date = ''; $data = array('ContentType' => 'STORY'); $codes = array(); $parse_result = parsenewsmlfile($bloghome . "/" . $delivery_dir . "/" . $file, &$head, &$body, &$codes, &$date, &$data); $a_loc = $bloghome . "/" . ($parse_result ? $archive_dir : $failure_dir) . "/" . $file; rename($bloghome . "/" . $delivery_dir . "/" . $file, $a_loc); if ($parse_result) { $node = newstory($head, $body, $codes, $date, $data); } if ($seo_writeback) { appendSEOData($node, $a_loc, $site_basepath); } unset($node); unset($file); unset($head); unset($body); unset($date); unset($date); unset($codes); } $user = $orig_user; session_save_session($old_state);