/** * @return array */ private function artefacts() { $oldschema = []; $newschema = []; $current = DB::get_conn()->getSelectedDatabase(); foreach (DB::table_list() as $lowercase => $dbtablename) { $oldschema[$dbtablename] = DB::field_list($dbtablename); } $test = new SapphireTest(); $test->create_temp_db(); foreach (DB::table_list() as $lowercase => $dbtablename) { $newschema[$lowercase] = DB::field_list($dbtablename); } $test->kill_temp_db(); DB::get_conn()->selectDatabase($current); $artefacts = []; foreach ($oldschema as $table => $fields) { if (!isset($newschema[strtolower($table)])) { $artefacts[$table] = $table; continue; } foreach ($fields as $field => $spec) { if (!isset($newschema[strtolower($table)][$field])) { $artefacts[$table][$field] = $field; } } } return $artefacts; }
/** * The process to automatically construct data object output configurations, executed on project build. */ public function requireDefaultRecords() { parent::requireDefaultRecords(); // Grab the list of data objects that have been completely removed. foreach (DB::table_list() as $table) { // Delete existing output configurations for these data objects. if (!class_exists($table)) { $existing = DataObjectOutputConfiguration::get_one('DataObjectOutputConfiguration', array('IsFor = ?' => $table)); $this->deleteConfiguration($table, $existing); } } // Grab the list of all data object types, along with any inclusions/exclusions defined. $objects = ClassInfo::subclassesFor('DataObject'); $inclusions = self::$custom_inclusions; $exclusions = array_unique(array_merge(self::$exclusions, self::$custom_exclusions)); // Check existing output configurations for these data objects. foreach ($objects as $object) { $existing = DataObjectOutputConfiguration::get_one('DataObjectOutputConfiguration', array('IsFor = ?' => $object)); // Delete existing output configurations for invalid data objects, or for those excluded. if ($existing && (self::$disabled || get_parent_class($object) !== 'DataObject' || ClassInfo::classImplements($object, 'TestOnly') || count($inclusions) > 0 && !in_array($object, $inclusions) || count($inclusions) === 0 && in_array($object, $exclusions))) { $this->deleteConfiguration($object, $existing); } else { if (!$existing && !self::$disabled && get_parent_class($object) === 'DataObject' && !ClassInfo::classImplements($object, 'TestOnly') && (count($inclusions) > 0 && in_array($object, $inclusions) || count($inclusions) === 0 && !in_array($object, $exclusions))) { $this->addConfiguration($object); } } } }
/** * Update the database schema as required by this extension */ public function augmentDatabase() { $exist = DB::table_list(); if (!empty($exist) && array_search('ForumMember', $exist) !== false) { DB::query("UPDATE \"Member\", \"ForumMember\" " . "SET \"Member\".\"ClassName\" = 'Member'," . "\"Member\".\"ForumRank\" = \"ForumMember\".\"ForumRank\"," . "\"Member\".\"Occupation\" = \"ForumMember\".\"Occupation\"," . "\"Member\".\"Country\" = \"ForumMember\".\"Country\"," . "\"Member\".\"Nickname\" = \"ForumMember\".\"Nickname\"," . "\"Member\".\"FirstNamePublic\" = \"ForumMember\".\"FirstNamePublic\"," . "\"Member\".\"SurnamePublic\" = \"ForumMember\".\"SurnamePublic\"," . "\"Member\".\"OccupationPublic\" = \"ForumMember\".\"OccupationPublic\"," . "\"Member\".\"CountryPublic\" = \"ForumMember\".\"CountryPublic\"," . "\"Member\".\"EmailPublic\" = \"ForumMember\".\"EmailPublic\"," . "\"Member\".\"AvatarID\" = \"ForumMember\".\"AvatarID\"," . "\"Member\".\"LastViewed\" = \"ForumMember\".\"LastViewed\"" . "WHERE \"Member\".\"ID\" = \"ForumMember\".\"ID\""); echo "<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('ForumRole.TRANSFERSUCCEEDED', 'The data transfer has succeeded. However, to complete it, you must delete the ForumMember table. To do this, execute the query \\"DROP TABLE \'ForumMember\'\\".') . "</div>"; } }
public function testTablesAreCreated() { $tables = DB::table_list(); $check = array('versionableextensionstest_dataobject_test1_live', 'versionableextensionstest_dataobject_test2_live', 'versionableextensionstest_dataobject_test3_live', 'versionableextensionstest_dataobject_test1_versions', 'versionableextensionstest_dataobject_test2_versions', 'versionableextensionstest_dataobject_test3_versions'); // Check that the right tables exist foreach ($check as $tableName) { $this->assertContains($tableName, array_keys($tables), 'Contains table: ' . $tableName); } }
public function run($request) { $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/dbip-city.csv'; if (!file_exists($strCSVPath)) { echo "<p>I cant find the dbip-city.csv file to import any data.<br>\n\t\t\t\tPlease download any database from <a href='https://db-ip.com/db/'>https://db-ip.com/db/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`Region`,`City`\n\t\t\t\t</p>"; //"0.0.0.0","0.255.255.255","US","California","Los Angeles" } else { if (!isset($_REQUEST['confirm'])) { $strLink = Director::baseURL() . 'dev/tasks/ImportDBIPcom?confirm=1'; echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>"; } else { increase_time_limit_to(); // // this needs varbinary fields so create the table here // $arr = DB::table_list(); if (!in_array('dbip_lookup', $arr)) { $strSQL = "CREATE TABLE `dbip_lookup` (\n\t\t\t\t\t `addr_type` enum('ipv4','ipv6') NOT NULL,\n\t\t\t\t\t `ip_start` varbinary(16) NOT NULL,\n\t\t\t\t\t `ip_end` varbinary(16) NOT NULL,\n\t\t\t\t\t `country` char(2) NOT NULL,\n\t\t\t\t\t `stateprov` varchar(80) NOT NULL,\n\t\t\t\t\t `city` varchar(80) NOT NULL,\n\t\t\t\t\t PRIMARY KEY (`ip_start`)\n\t\t\t\t\t);"; DB::query($strSQL); } if (isset($_REQUEST['emptydb'])) { DB::query('TRUNCATE `dbip_lookup`;'); } $conn = DB::get_conn(); if ($conn->supportsTransactions()) { $conn->transactionStart(); } $handle = fopen($strCSVPath, "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $line = str_replace('","', '___', $line); $line = str_replace('"', '', $line); $arrParts = Convert::raw2sql(explode("___", $line)); $vals = array('addr_type' => "'" . IpToLocation::addr_type($arrParts[0]) . "'", 'ip_start' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[0])) . "'", 'ip_end' => "'" . $conn->escapeString(ContinentalContentUtils::IPAddressToIPNumber($arrParts[1])) . "'", 'country' => "'" . $arrParts[2] . "'", 'stateprov' => "'" . $arrParts[3] . "'", 'city' => "'" . $arrParts[4] . "'"); $fields = array_keys($vals); DB::query('INSERT INTO `dbip_lookup` (`' . implode('`,`', $fields) . '`) VALUES (' . implode(',', $vals) . ')'); } fclose($handle); } else { echo 'Error opening file'; } if ($conn->supportsTransactions()) { $conn->transactionEnd(); } } } }
public function testVersionedWithSingleStage() { $tables = DB::table_list(); $this->assertContains('versionedtest_singlestage', array_keys($tables), 'Contains base table'); $this->assertContains('versionedtest_singlestage_versions', array_keys($tables), 'Contains versions table'); $this->assertNotContains('versionedtest_singlestage_live', array_keys($tables), 'Does not contain separate table with _Live suffix'); $this->assertNotContains('versionedtest_singlestage_stage', array_keys($tables), 'Does not contain separate table with _Stage suffix'); Versioned::reading_stage("Stage"); $obj = new VersionedTest_SingleStage(array('Name' => 'MyObj')); $obj->write(); $this->assertNotNull(VersionedTest_SingleStage::get()->byID($obj->ID), 'Writes to and reads from default stage if its set explicitly'); Versioned::reading_stage("Live"); $obj = new VersionedTest_SingleStage(array('Name' => 'MyObj')); $obj->write(); $this->assertNotNull(VersionedTest_SingleStage::get()->byID($obj->ID), 'Writes to and reads from default stage even if a non-matching stage is set'); }
/** * Create a database table to replay the site tree creation, based on the chronological order of the site tree version table. */ protected function setupStructure() { if (!DB::get_conn() instanceof MySQLDatabase) { exit('This task currently only supports <strong>MySQL</strong>...'); } $replaceArray = self::$db_columns; unset($replaceArray['FullURL']); $this->replaceColumnString = implode(',', array_keys($replaceArray)); $tableList = DB::table_list(); if (self::$use_temporary_table || !in_array(self::$default_table, $tableList)) { $options = self::$use_temporary_table ? array('temporary' => true) : null; $this->replayTable = DB::create_table(self::$default_table, self::$db_columns, null, $options); } else { // Delete all records from the table. $query = new SQLDelete(self::$default_table); $query->execute(); } }