public function migrateLegacyFiles($dry_run = TRUE) { $this->dry_run = $dry_run; require_once PA::$path . "/db/Dal/DbUpdate.php"; echo "Migrating legacy files to new storage system\n"; $this->all_files = array(); if (!($h = opendir(PA::$path . '/web/files'))) { throw new PAException(GENERAL_SOME_ERROR, "Unable to open web/files directory"); } while (false !== ($f = readdir($h))) { if ($f[0] == '.') { continue; } $this->all_files[$f] = TRUE; } closedir($h); $this->unmatched = count($this->all_files); $this->unmatchable = 0; $this->matched = 0; $this->dupes = 0; echo "{$this->unmatched} files found\n"; echo "Matching with user images ...\n"; $sql = Dal::validate_sql("SELECT user_id,picture FROM {users}", $network); $sth = Dal::query($sql); while ($r = Dal::row($sth)) { list($uid, $pic) = $r; // user avatar $this->_matchLegacyFile($pic, array("role" => "avatar", "user" => $uid)); //TODO: user header image } $this->_dumpMatchResults(); $networks = DbUpdate::get_valid_networks(); echo "Processing " . count($networks) . " networks\n"; foreach ($networks as $network) { echo " Network: {$network}\n"; // network level stuff list($network_id, $act, $logo, $extra) = Dal::query_one("SELECT network_id, is_active, inner_logo_image, extra FROM networks WHERE address=?", array($network)); assert($act); // sanity check $extra = unserialize($extra); // network avatar $this->_matchLegacyFile($logo, array("role" => "avatar", "network" => $network_id)); // network header image $header_image = @$extra["basic"]["header_image"]["name"]; if (!empty($header_image)) { $this->_matchLegacyFile($header_image, array("role" => "header", "network" => $network_id)); } // emblems foreach (unserialize(Dal::query_first(Dal::validate_sql("SELECT data FROM {moduledata} WHERE modulename='LogoModule'"))) as $emblem) { $this->_matchLegacyFile($emblem["file_name"], array("role" => "emblem", "network" => $network_id)); } // group pictures $sth = Dal::query(Dal::validate_sql("SELECT collection_id, picture FROM {contentcollections} WHERE type=1 AND is_active=1", $network)); while ($r = Dal::row($sth)) { list($cid, $pic) = $r; $this->_matchLegacyFile($pic, array("role" => "avatar", "network" => $network_id, "group" => $cid)); $header = Dal::query_first(Dal::validate_sql("SELECT header_image FROM groups WHERE group_id=?", $network), array($cid)); $this->_matchLegacyFile($header, array("role" => "header", "network" => $network_id, "group" => $cid)); } /* disabled until we update peopleaggregator.net $sth = Dal::query(Dal::validate_sql("SELECT group_id, header_image FROM {groups}", $network)); while ($r = Dal::row($sth)) { list ($gid, $pic) = $r; $this->_matchLegacyFile($network, "group", $gid, $pic); } */ //TODO: advertisements // images, audio, video foreach (array("image", "audio", "video") as $table) { $sth = Dal::query(Dal::validate_sql('SELECT mc.content_id, mc.' . $table . '_file, c.author_id, c.collection_id, c.is_active FROM {' . $table . 's} mc LEFT JOIN {contents} c ON mc.content_id=c.content_id HAVING c.is_active=1', $network)); while ($r = Dal::row($sth)) { list($cid, $fn, $uid, $ccid, $act) = $r; $this->_matchLegacyFile($fn, array("role" => "media", "network" => $network_id, "content" => $cid)); } } } $this->_dumpMatchResults(); foreach ($this->all_files as $fn => $v) { if ($v === TRUE) { echo " * unmatchable: {$fn}\n"; } } echo "Overall results from web/files: "; $this->_dumpMatchResults(); }
function main() { $this->db = Dal::get_connection(); $this->note("Doing database update"); // We use $this->db->getOne() below instead of Dal::query_one() as // the first time this script is run, the mc_db_status table will // not exist, which will fire an exception with Dal::query_one() // and break the installation. Please don't change this to // Dal::query_one()! -PP 2006-11-15 $db_status = $this->db->getOne("SELECT * FROM mc_db_status LIMIT 1"); if (!DB::isError($db_status)) { $this->note("mc_db_status table in place"); } else { $this->note("Creating mc_db_status table"); $this->query("CREATE TABLE mc_db_status (stmt_key VARCHAR(255) NOT NULL, PRIMARY KEY(stmt_key))"); } // add network column if (!$this->column_exists("mc_db_status", "network")) { $this->query("ALTER TABLE mc_db_status ADD COLUMN network VARCHAR(50) NOT NULL DEFAULT ''"); $this->query("ALTER TABLE mc_db_status DROP PRIMARY KEY"); $this->query("ALTER TABLE mc_db_status ADD PRIMARY KEY(stmt_key, network)"); } /* 'broken' col disabled for now - use $this->broken_networks instead. // make sure the network table has the 'broken' column before we get started if (!$this->column_exists("networks", "broken")) { Dal::query("ALTER TABLE networks ADD COLUMN broken BOOLEAN DEFAULT '0'"); }*/ // find networks which have their tables (i.e. skip over broken networks) $this->networks = DbUpdate::get_valid_networks(); $override = @$_GET['override']; if (!empty($override)) { try { Dal::query("INSERT INTO mc_db_status SET stmt_key=?", Array($override)); } catch (PAException $e) { echo "<p>exception trying to override: ".$e->getMessage()."</p>"; } } $this->do_updates(); if (!$this->quiet) { // $this->dump_schema(); $this->note("db update done."); } }
<?php require_once dirname(__FILE__) . '/../config.inc'; require_once "{$path_prefix}/db/Dal/Dal.php"; require_once "{$path_prefix}/db/Dal/DbUpdate.php"; require_once "{$path_prefix}/api/Network/Network.php"; // Re-include constants.php to make sure we have the most up to date // constants. If we are in the middle of an update and this script is // being included by web/update/run_scripts.php, we might not have all // the constants. include "{$path_prefix}/web/includes/constants.php"; // $settings_new contains the mapping of page names to modules they contain. global $settings_new; $db = Dal::get_connection(); foreach (DbUpdate::get_valid_networks() as $net_address) { set_time_limit(30); $net = Network::get_network_by_address($net_address); $table_name = 'page_default_settings'; if ($net->type != MOTHER_NETWORK_TYPE) { // 1 for home network $table_name = $net->address . '_' . $table_name; } $sql = ' TRUNCATE TABLE ' . $table_name; $res = Dal::query($sql); foreach ($settings_new as $page_id => $v1) { $page_name = $v1['page_name']; $data = $v1['data']; $settings_data = serialize($data); $is_configurable = isset($v1['is_configurable']) ? $v1['is_configurable'] : FALSE; //default value will be false is not specified $sql = "INSERT INTO {$table_name} (page_id, page_name, default_settings, is_configurable) VALUES (?, ?, ?, ?)";
function main() { $this->db = Dal::get_connection(); $this->write('<table>'); $this->note('Doing database update'); // We use $this->db->getOne() below instead of Dal::query_one() as // the first time this script is run, the mc_db_status table will // not exist, which will fire an exception with Dal::query_one() // and break the installation. Please don't change this to // Dal::query_one()! -PP 2006-11-15 $db_status = $this->db->getOne('SELECT * FROM mc_db_status LIMIT 1'); if (!DB::isError($db_status)) { $this->note('mc_db_status table in place'); } else { $this->note('Creating mc_db_status table'); $this->query('CREATE TABLE mc_db_status (stmt_key VARCHAR(255) NOT NULL, PRIMARY KEY(stmt_key))'); } // add network column if (!$this->column_exists('mc_db_status', 'network')) { $this->query('ALTER TABLE mc_db_status ADD COLUMN network VARCHAR(50) NOT NULL DEFAULT \'\''); $this->query('ALTER TABLE mc_db_status DROP PRIMARY KEY'); $this->query('ALTER TABLE mc_db_status ADD PRIMARY KEY(stmt_key, network)'); } // find networks which have their tables (i.e. skip over broken networks) $this->networks = DbUpdate::get_valid_networks(); $override = @$_GET['override']; if (!empty($override)) { try { Dal::query('INSERT INTO mc_db_status SET stmt_key=?', array($override)); } catch (PAException $e) { echo '<p>exception trying to override: ', $e->getMessage(), '</p>'; } } $this->do_updates(); if (!$this->quiet) { $this->note('CORE db updates done.'); $this->write('</table>'); } }