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'); } }
/** * 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); } }
<?php if (!extension_loaded('midgard2')) { throw new midcom_error("This script requires Midgard2"); } midcom::get('auth')->require_valid_user('basic'); midcom::get('auth')->require_admin_user(); 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";
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'); }