public function prepare_storage() { // Generate tables midgard_storage::create_base_storage(); // And update as necessary $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if ($refclass->isAbstract() || $refclass->isInterface()) { continue; } $type = $refclass->getName(); if (!is_subclass_of($type, 'MidgardDBObject')) { continue; } if (midgard_storage::class_storage_exists($type)) { // FIXME: Skip updates until http://trac.midgard-project.org/ticket/1426 is fixed continue; if (!midgard_storage::update_class_storage($type)) { $this->markTestSkipped('Could not update ' . $type . ' tables in test database'); } continue; } if (!midgard_storage::create_class_storage($type)) { $this->markTestSkipped('Could not create ' . $type . ' tables in test database'); } } // And update as necessary return; if (!midgard_user::auth('root', 'password')) { echo "auth failed\n"; $this->markTestSkipped('Could not authenticate as ROOT'); } }
public function post_database(array $args) { midgardmvc_core::get_instance()->authorization->require_admin(); if (isset($_POST['update'])) { //Disable limits // TODO: Could this be done more safely somehow @ini_set('memory_limit', -1); @ini_set('max_execution_time', 0); midgardmvc_core::get_instance()->dispatcher->get_midgard_connection()->set_loglevel('debug'); if (!class_exists('midgard_storage')) { // Midgard1 or Midgard2 9.03 if (!midgard_config::create_midgard_tables()) { throw new Exception("Could not create Midgard class tables"); } // And update as necessary $mgdschema_types = midgardmvc_core::get_instance()->dispatcher->get_mgdschema_classes(); foreach ($mgdschema_types as $type) { if (midgard_config::class_table_exists($type)) { midgardmvc_core::get_instance()->log('midgardmvc_core_controllers_about::post_database', "Updating database table for type {$type}", 'debug'); if (!midgard_config::update_class_table($type)) { throw new Exception('Could not update ' . $type . ' tables in test database'); } continue; } midgardmvc_core::get_instance()->log('midgardmvc_core_controllers_about::post_database', "Creating database table for type {$type}", 'debug'); if (!midgard_config::create_class_table($type)) { throw new Exception('Could not create ' . $type . ' tables in test database'); } } } else { // Midgard2 9.09 or newer /*if (!midgard_storage::create_base_storage()) { throw new Exception("Could not create Midgard class tables"); }*/ // And update as necessary $mgdschema_types = midgardmvc_core::get_instance()->dispatcher->get_mgdschema_classes(); foreach ($mgdschema_types as $type) { if (midgard_storage::class_storage_exists($type)) { midgardmvc_core::get_instance()->log('midgardmvc_core_controllers_about::post_database', "Updating storage for type {$type}", 'debug'); if (!midgard_storage::update_class_storage($type)) { //throw new Exception('Could not update ' . $type . ' storage'); } continue; } midgardmvc_core::get_instance()->log('midgardmvc_core_controllers_about::post_database', "Creating storage for type {$type}", 'debug'); if (!midgard_storage::create_class_storage($type)) { //throw new Exception('Could not create ' . $type . ' storage'); } } } midgardmvc_core::get_instance()->dispatcher->get_midgard_connection()->set_loglevel(midgardmvc_core::get_instance()->configuration->get('log_level')); } $this->get_database($args); }
/** * Prepares a mgd2 database */ function openpsa_prepare_database($config) { if (!$config->create_blobdir()) { throw new Exception("Failed to create file attachment storage directory to {$config->blobdir}:" . midgard_connection::get_instance()->get_error_string()); } // Create storage if (!midgard_storage::create_base_storage()) { if (midgard_connection::get_instance()->get_error_string() != 'MGD_ERR_OK') { throw new Exception("Failed to create base database structures" . midgard_connection::get_instance()->get_error_string()); } } $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if (!$refclass->isSubclassOf('midgard_object')) { continue; } $type = $refclass->getName(); midgard_storage::create_class_storage($type); midgard_storage::update_class_storage($type); } }
midcom::get()->disable_limits(); while (@ob_end_flush()) { } echo "<pre>\n"; echo "<h1>Update Class Storage</h1>\n"; flush(); midgard_storage::create_base_storage(); echo " Created base storage\n"; $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); $counter = 0; $start = microtime(true); foreach ($classes as $refclass) { if (!$refclass->isSubclassOf('midgard_object')) { continue; } $type = $refclass->getName(); $counter++; if (midgard_storage::class_storage_exists($type)) { midgard_storage::update_class_storage($type); echo " Updated storage for {$type}\n"; } else { midgard_storage::create_class_storage($type); echo " Created storage for {$type}\n"; } flush(); } echo "Processed " . $counter . " schema types in " . round(microtime(true) - $start, 2) . "s"; echo "\n\nDone."; echo "</pre>"; ob_start();
private function _prepare_database(\midgard_config $config) { $this->_io->write('Preparing storage <comment>(this may take a while)</comment>'); $midgard = \midgard_connection::get_instance(); $midgard->open_config($config); if (!$midgard->is_connected()) { throw new \Exception("Failed to open config {$config->database}:" . $midgard->get_error_string()); } if (!$config->create_blobdir()) { throw new \Exception("Failed to create file attachment storage directory to {$config->blobdir}:" . $midgard->get_error_string()); } // Create storage if (!\midgard_storage::create_base_storage()) { if ($midgard->get_error_string() != 'MGD_ERR_OK') { throw new \Exception("Failed to create base database structures" . $midgard->get_error_string()); } } $re = new \ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if (!$refclass->isSubclassOf('midgard_object')) { continue; } $type = $refclass->getName(); \midgard_storage::create_class_storage($type); \midgard_storage::update_class_storage($type); } $this->_io->write('Storage created'); }