Example #1
0
 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');
     }
 }
Example #2
0
 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);
 }
Example #3
0
/**
 * 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);
    }
}
Example #4
0
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();
Example #5
0
}
// This will create any classes that might be missing
midgard_storage::create_base_storage();
echo "  Created base storage\n";
$re = new ReflectionExtension('midgard2');
$classes = $re->getClasses();
foreach ($classes as $refclass) {
    if (!$refclass->isSubclassOf('midgard_object')) {
        continue;
    }
    $type = $refclass->getName();
    midgard_storage::update_class_storage($type);
    echo "  Updated storage for {$type}\n";
}
//No idea why this has to be listed explicitly...
midgard_storage::update_class_storage('MidgardRepligard');
echo "  Updated storage for MidgardRepligard\n";
//Copy stuff from multilang tables by doing straight SQL
$m_tables = array('topic', 'article', 'element', 'net_nemein_redirector_tinyurl', 'org_openpsa_products_product_group', 'org_openpsa_products_product', 'pageelement', 'page', 'snippet', 'topic');
$db = mysql_connect($config->host, $config->dbuser, $config->dbpass) or die(mysql_error());
mysql_select_db($config->database, $db);
mysql_set_charset('utf8', $db);
$res = mysql_query('SET NAMES utf8', $db) or die(mysql_error());
foreach ($m_tables as $table) {
    $stmt = 'UPDATE ' . $table . ', ' . $table . '_i SET ' . $table . '.';
    switch ($table) {
        case 'topic':
            $stmt .= 'title = ' . $table . '_i.title, ' . $table . '.extra = ' . $table . '_i.extra, ' . $table . '.description = ' . $table . '_i.description';
            break;
        case 'snippet':
            $stmt .= 'code = ' . $table . '_i.code, ' . $table . '.doc = ' . $table . '_i.doc';
Example #6
0
 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');
 }