function merge_table(GDO_Database $db_from, GDO_Database $db_to, $classname) { GWF_Cronjob::notice(sprintf('Merging table %s', $classname)); GDO::setCurrentDB($db_from); $fromtable = GDO::table($classname); if (false === ($result = $fromtable->select('*'))) { return false; } GDO::setCurrentDB($db_to); $totable = GDO::table($classname); while (false !== ($row = $fromtable->fetch($result))) { GWF_Cronjob::notice(sprintf('Merging table %s ID %s', $classname, reset($row))); $totable->insertAssoc($row, GDO::ARRAY_A); } $fromtable->free($result); return true; }
private static function fix_missing_site_threads(GDO_Database $db_from, GDO_Database $db_to, array &$db_offsets) { GDO::setCurrentDB($db_to); $table = GDO::table('WC_Site'); $module = GWF_Module::getModule('WeChall'); // Boards // if (false === ($result = $table->select('*'))) // { // echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); // return false; // } // while (false !== ($site = $table->fetch($result, GDO::ARRAY_O))) // { // $site instanceof WC_Site; // if (false === GDO::table('GWF_ForumBoard')->select('1', "board_id={$site->getBoardID()}")) // { // GWF_Cronjob::notice(sprintf('Site %s has no board!', $site->getClassName())); // $site->onCreateBoard(); // } // } // $table->free($result); // Threads if (false === ($result = $table->select('*'))) { echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); return false; } while (false !== ($site = $table->fetch($result, GDO::ARRAY_O))) { $site instanceof WC_Site; if (false === $site->getThread()) { GWF_Cronjob::notice(sprintf('Site %s has no thread!', $site->getClassName())); $site->onCreateThread($module); } } $table->free($result); }
private static function cronjobsSession() { GWF_Cronjob::start('Session'); $table = GDO::table('GWF_Session'); $cut = time() - GWF_SESS_LIFETIME; if (false === $table->deleteWhere("sess_time<{$cut}")) { echo GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } elseif (0 < ($affected = $table->affectedRows())) { GWF_Cronjob::notice(sprintf('Deleted %s sesssions.', $affected)); } GWF_Cronjob::end('Session'); }
chdir('../../../www'); require_once 'protected/config.php'; require_once '../gwf3.class.php'; $gwf = new GWF3(getcwd(), array('init' => true, 'bootstrap' => false, 'website_init' => true, 'autoload_modules' => false, 'load_module' => false, 'start_debug' => true, 'get_user' => false, 'do_logging' => false, 'buffered_log' => false, 'log_request' => false, 'blocking' => false, 'no_session' => true, 'store_last_url' => false, 'ignore_user_abort' => false, 'kick_banned_ip' => false)); require_once 'merge/mergefuncs.php'; GWF_Log::init(false, 0x7fffffff, 'protected/logs/merge'); if ($argc !== 6) { merge_usage(); } GWF_Log::logCron('======================'); GWF_Log::logCron('=== STARTING MERGE ==='); GWF_Log::logCron('======================'); if (false === ($db_from = merge_db($argv))) { GWF_Log::logCritical('Connection to the import db failed!'); } $db_to = gdo_db(); // Store some offsets, like highest user(sic) => 1234 $db_offsets = array(); $prefix = $argv[4]; $prevar = $argv[5]; $modules = GWF_ModuleLoader::loadModulesFS(); $modules = GWF_ModuleLoader::sortModules($modules, 'module_priority', 'ASC'); GWF_Log::logCron('=== LOADED MODULES ==='); GWF_Log::logCron('======================'); merge_core($db_from, $db_to, $db_offsets, $prefix, $prevar); foreach ($modules as $module) { $module instanceof GWF_Module; GWF_Cronjob::notice(sprintf('MERGE MODULE %s', $module->getName())); GWF_ModuleLoader::includeAll($module); $module->onMerge($db_from, $db_to, $db_offsets, $prefix, $prevar); }