private function midgard2Connect() { $filepath = ini_get('midgard.configuration_file'); $config = new \midgard_config(); $config->read_file_at_path($filepath); $mgd = \midgard_connection::get_instance(); if (!$mgd->open_config($config)) { throw new \PHPCR\RepositoryException($mgd->get_error_string()); } return $mgd; }
public function __construct() { if (ini_get('midgard.http') == 1) { throw new LogicException("midgard.http should be set to 'Off', while running via AiP"); } // opening connection $filepath = get_cfg_var("midgard.configuration_file"); $config = new midgard_config(); $config->read_file_at_path($filepath); $this->mgd = midgard_connection::get_instance(); $this->mgd->open_config($config); // starting mvc $application_config = get_cfg_var('midgardmvc.application_config'); if (!$application_config) { $application_config = MIDGARDMVC_ROOT . '/application.yml'; } $mvc = midgardmvc_core::get_instance($application_config); }
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); }
/** * Setup file for running unit tests * * Usage: phpunit --no-globals-backup ./ */ $mgd_defaults = array('argv' => array(), 'user' => 0, 'admin' => false, 'root' => false, 'auth' => false, 'cookieauth' => false, 'page' => 0, 'debug' => false, 'self' => '/', 'prefix' => '', 'host' => 0, 'style' => 0, 'author' => 0, 'config' => array('prefix' => '', 'quota' => false, 'unique_host_name' => 'openpsa', 'auth_cookie_id' => 1), 'schema' => array('types' => array())); $GLOBALS['midcom_config_local'] = array(); // Check that the environment is a working one if (extension_loaded('midgard2')) { $GLOBALS['midcom_config_local']['person_class'] = 'openpsa_person'; // Open connection $midgard = midgard_connection::get_instance(); // Workaround for https://github.com/midgardproject/midgard-php5/issues/49 if (!$midgard->is_connected() && ($path = ini_get('midgard.configuration_file'))) { $config = new midgard_config(); $config->read_file_at_path($path); $midgard->open_config($config); } // if we still can't connect to a DB, we'll create a new one if (!$midgard->is_connected()) { $config = new midgard_config(); $config->dbtype = 'SQLite'; $config->database = 'openpsa_test'; $config->blobdir = OPENPSA_TEST_ROOT . '__output/blobs'; $config->logfilename = OPENPSA_TEST_ROOT . '__output/midgard2.log'; $config->tablecreate = true; $config->tableupdate = true; $config->loglevel = 'warn'; if (!$midgard->open_config($config)) { throw new Exception('Could not open Midgard connection to test database: ' . $midgard->get_error_string());
foreach ($argv as $arg) { switch ($arg) { case '-h': help($cmd); break; case '-b': if (isset($argv[$pos + 1])) { $package = $argv[$pos + 1]; } break; case '-v': if (isset($argv[$pos + 1])) { $version = $argv[$pos + 1]; } break; case '-p': if (isset($argv[$pos + 1])) { $project = $argv[$pos + 1]; } break; } ++$pos; } if ($package) { $config = new midgard_config(); $config->read_file_at_path($filepath); $mgd = midgard_connection::get_instance(); $mgd->open_config($config); } else { usage($cmd); }
<?php /** * Converter script for mgd1 databases. Use at you own risk, and remember to backup before! */ if (count($argv) != 2) { die("Usage: php update_db.php midgardconffile\n"); } if (!extension_loaded('midgard2')) { die("Midgard2 is not installed in your PHP environment.\n"); } // Create a config file $config = new midgard_config(); if (!$config->read_file($argv[1], false)) { die("Failed to load Midgard2 config file"); } // Open a DB connection with the config $midgard = midgard_connection::get_instance(); if (!$midgard->open_config($config)) { die("Failed to open Midgard database connection to {$argv[1]}: " . $midgard->get_error_string() . "\n"); } // 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();
private function _create_config($config_name) { $project_basedir = $this->_get_basedir(); $openpsa_basedir = realpath($project_basedir . '/vendor/openpsa/midcom/'); $project_name = basename($project_basedir); self::_prepare_dir('config'); self::_prepare_dir('config/share'); self::_prepare_dir('config/share/views'); self::_prepare_dir('config/share/schema'); self::_prepare_dir('var'); self::_prepare_dir('var/cache'); self::_prepare_dir('var/rcs'); self::_prepare_dir('var/blobs'); self::_prepare_dir('var/log'); self::_link($openpsa_basedir . '/config/midgard_auth_types.xml', $project_basedir . '/config/share/midgard_auth_types.xml', $this->_io); self::_link($openpsa_basedir . '/config/MidgardObjects.xml', $project_basedir . '/config/share/MidgardObjects.xml', $this->_io); // Create a config file $config = new \midgard_config(); $config->dbtype = 'MySQL'; $config->dbuser = $this->_io->ask('<question>DB username:</question> [<comment>' . $project_name . '</comment>] ', $project_name); $config->dbpass = $this->_io->askAndHideAnswer('<question>DB password:</question> '); $config->database = $this->_io->ask('<question>DB name:</question> [<comment>' . $project_name . '</comment>] ', $project_name); $config->blobdir = $project_basedir . '/var/blobs'; $config->sharedir = $project_basedir . '/config/share'; $config->vardir = $project_basedir . '/var'; $config->cachedir = $project_basedir . '/var/cache'; $config->logfilename = $project_basedir . '/var/log/midgard.log'; $config->loglevel = 'warn'; $target_path = getenv('HOME') . '/.midgard2/conf.d/' . $project_name; if (!$config->save_file($project_name, true)) { throw new \Exception("Failed to save config file " . $target_path); } $this->_io->write("Configuration file <info>" . $target_path . "</info> created."); self::_link($target_path, $project_basedir . '/config/midgard2.ini', $this->_io); return $config; }
private function _create_config($config_file) { $this->_check_dir('/var/lib/' . $this->_project_name); $this->_check_dir('/var/cache/' . $this->_project_name); $this->_link_file('config', 'midgard_auth_types.xml', '/var/lib/' . $this->_project_name . '/share'); $this->_link_file('config', 'MidgardObjects.xml', '/var/lib/' . $this->_project_name . '/share'); $this->_check_dir('/var/lib/' . $this->_project_name . '/share/views'); $this->_check_dir('/var/lib/' . $this->_project_name . '/rcs'); // Create a config file $config = new midgard_config(); $config->dbtype = 'SQLite'; $config->database = $this->_project_name; $config->dbdir = '/var/lib/' . $this->_project_name; $config->blobdir = '/var/lib/' . $this->_project_name . '/blobs'; $config->sharedir = '/var/lib/' . $this->_project_name . '/share'; $config->vardir = '/var/lib/' . $this->_project_name; $config->cachedir = '/var/cache/' . $this->_project_name; $config->logfilename = '/var/log/' . $this->_project_name . '/midgard.log'; $config->loglevel = 'debug'; if (!$config->save_file($this->_project_name, false)) { $this->fail("Failed to save " . $config_file); } if (!chown($config_file, $this->_user)) { $this->fail("Failed to set permissions to " . $this->_user . ' on ' . $config_file); } $this->output("Configuration file " . $config_file . " created."); return $config; }
<?php if (count($argv) != 2) { die("Usage: php quick_init.php midgardconffile\n"); } if (!extension_loaded('midgard2')) { die("Midgard2 is not installed in your PHP environment.\n"); } if (!class_exists('midgardmvc_core_node')) { die("Midgard MVC or its schemas are not installed in your Midgard environment.\n"); } // Create a config file $config = new midgard_config(); $config->dbtype = 'SQLite'; $config->database = $argv[1]; $config->tablecreate = true; $config->tableupdate = true; $config->loglevel = 'warning'; // Save it to ~/.midgard2 $config->save_file($argv[1], true); echo "Configuration file ~/.midgard2/conf.d/{$argv[1]} created.\n"; // Open a DB connection with the config $midgard = midgard_connection::get_instance(); if (!$midgard->open_config($config)) { die("Failed to open Midgard database connection to {$argv[1]}: " . $midgard->get_error_string() . "\n"); } // Create storage midgard_storage::create_base_storage(); echo "Database initialized, preparing storage for MgdSchema classes:\n"; $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses();
<?php $GLOBALS['midcom_config_local'] = array(); // Check that the environment is a working one if (extension_loaded('midgard2')) { if (!class_exists('midgard_topic')) { throw new Exception('You need to install OpenPSA MgdSchemas from the "schemas" directory to the Midgard2 schema directory'); } // Initialize the $_MIDGARD superglobal $_MIDGARD = array('argv' => array(), 'user' => 0, 'admin' => false, 'root' => false, 'auth' => false, 'cookieauth' => false, 'page' => 0, 'debug' => false, 'host' => 0, 'style' => 0, 'author' => 0, 'config' => array('prefix' => '', 'quota' => false, 'unique_host_name' => 'openpsa', 'auth_cookie_id' => 1), 'schema' => array()); $GLOBALS['midcom_config_local']['person_class'] = 'openpsa_person'; $midgard = midgard_connection::get_instance(); // Workaround for https://github.com/midgardproject/midgard-php5/issues/49 if (!$midgard->is_connected()) { $config = new midgard_config(); $config->read_file_at_path(ini_get('midgard.configuration_file')); $midgard->open_config($config); } if (method_exists($midgard, 'enable_workspace')) { $midgard->enable_workspace(false); } // workaround for segfaults that might have something to do with https://bugs.php.net/bug.php?id=51091 // see also https://github.com/midgardproject/midgard-php5/issues/50 if (function_exists('gc_enabled') && gc_enabled()) { gc_disable(); } } else { if (!extension_loaded('midgard')) { throw new Exception("OpenPSA requires Midgard PHP extension to run"); } }