/**
  * Get current connection
  *
  * @return \Doctrine\DBAL\Driver\Connection|\Doctrine\DBAL\Connection|\Blast\Orm\Connection
  */
 public function getConnection()
 {
     if (null === $this->connection) {
         $this->connection = ConnectionManager::getInstance()->get();
     }
     return $this->connection;
 }
 function main()
 {
     $this->Auth = new AuthComponent(null);
     $this->out('Migracion de base de datos RFIETP');
     $this->hr();
     $this->out('Introduzca la version a la que desea migrar (por ej: 1.7 o "q" para salir):');
     $user_version = trim($this->in(''));
     if ($user_version != 'q') {
         $this->out('Chequeando version de base de datos...');
         $db = ConnectionManager::getInstance();
         $conn = $db->getDataSource('default');
         $res = $conn->query('SELECT * FROM version ORDER BY id DESC;');
         $current_version = $res[0][0]['version'];
         $this->out($current_version);
         if (version_compare($user_version, $current_version) == 1) {
             // actualiza version => ejecuta script en BD
             if (file_exists(sprintf(NOMBRE_ARCHIVO, $user_version))) {
                 // ejecuta script sql
                 $sql = file_get_contents(sprintf(NOMBRE_ARCHIVO, $user_version), true);
                 $conn->query($sql);
                 // actualiza version de BD
                 $conn->query("INSERT INTO version (version, fecha) VALUES ('" . $user_version . "', NOW())");
                 $this->out("La base de datos se ha actualizado a la version " . $user_version);
             } else {
                 $this->out("El archivo " . sprintf(NOMBRE_ARCHIVO, $user_version) . " no existe. Proceso abortado!");
             }
         } else {
             $this->out("");
             $this->out("La versión actual " . $current_version . " es mayor que " . $user_version);
         }
     }
     $this->out("");
     $this->hr();
 }
 /**
  * Prepare "environment" for invocation on bean method. Configures
  * the PropertyManager (always), the Logger (if log.ini has been provided
  * with the bean) and ConnectionManager (if database.ini has been provided
  * with the bean).
  *
  */
 protected function prepare()
 {
     if ($this->configuration['log.ini']) {
         Logger::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/log.ini')));
     }
     if ($this->configuration['database.ini']) {
         ConnectionManager::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/database.ini')));
     }
 }
 /**
  * Returns an instance with a given number of DSNs
  *
  * @param   [:string] dsns
  * @return  rdbms.ConnectionManager
  */
 protected function instanceWith($dsns)
 {
     $properties = '';
     foreach ($dsns as $name => $dsn) {
         $properties .= '[' . $name . "]\ndsn=\"" . $dsn . "\"\n";
     }
     $cm = ConnectionManager::getInstance();
     $cm->configure(Properties::fromString($properties));
     return $cm;
 }
Exemple #5
0
 function _preflight_check()
 {
     App::import('Model', 'ConnectionManager');
     $errorMessage = "\nYou need to create an entry for your joomla " . "database in croogo's configuration file.\n";
     $connectionManager = ConnectionManager::getInstance();
     if (!property_exists($connectionManager->config, 'joomla')) {
         $this->out($errorMessage);
         exit;
     }
 }
 /**
  * Returns an instance with a given number of DSNs
  *
  * @param   [:string] dsns
  * @return  rdbms.ConnectionManager
  */
 protected function instanceWith($dsns)
 {
     $cm = ConnectionManager::getInstance();
     foreach ($dsns as $name => $dsn) {
         if (FALSE !== ($p = strpos($name, '.'))) {
             $cm->queue($dsn, substr($name, 0, $p), substr($name, $p + 1));
         } else {
             $cm->queue($dsn, $name);
         }
     }
     return $cm;
 }
Exemple #7
0
 /**
  * Constructor.
  *
  * @return void
  * @access private
  */
 function __construct($id = false, $table = null, $ds = null, $tablePrefix = null)
 {
     if ($tablePrefix) {
         $cm =& ConnectionManager::getInstance();
         if (!empty($cm->config->plugin['prefix'])) {
             $dbPrefix = $cm->config->plugin['prefix'];
         } else {
             $dbPrefix = '';
         }
         $this->tablePrefix = $dbPrefix . $tablePrefix;
     }
     parent::__construct();
 }
 /**
  * Confirm database connection and redirect accordingly
  */
 public function databaseconnection_check()
 {
     uses('model' . DS . 'connection_manager');
     $db = ConnectionManager::getInstance();
     @($connected = $db->getDataSource('default'));
     $message = 'Error: not able to connect to database';
     $cssClass = 'error';
     $action = 'database';
     if ($connected->isConnected()) {
         $message = 'Success: your database connection is now set';
         $cssClass = '';
         $action = 'bakesale';
     }
     $this->Session->setFlash($message, 'default', array('class' => $cssClass));
     $this->redirect(array('action' => $action));
 }
 function setup()
 {
     if (!empty($this->data)) {
         $data = $this->data;
         $install_files_path = CONFIGS . 'install' . DS;
         $connection = array();
         foreach (array('driver', 'host', 'login', 'password', 'database', 'prefix') as $k) {
             $connection[$k] = $data[$k];
         }
         $this->_writeDBConfig($connection);
         uses('model' . DS . 'connection_manager');
         $db = ConnectionManager::getInstance();
         $connection = $db->getDataSource('default');
         if ($connection->isConnected()) {
             App::import('vendor', 'migrations');
             $oMigrations = new Migrations();
             $oMigrations->load($install_files_path . 'schema.yml');
             $dbRes = $oMigrations->up();
             if (is_array($dbRes)) {
                 $error_string = '';
                 foreach ($dbRes as $error) {
                     $error_string .= $error['error'] . '<br />';
                 }
                 $this->Session->setFlash(__('There were some errors during the creation of your db tables', true) . ':<br />' . $error_string);
             } elseif ($dbRes == true) {
                 //add admin to the users table
                 App::import('model', array('User', 'Site'));
                 $User = new User();
                 $User->save(array('username' => $data['admin_username'], 'password' => sha1(Configure::read('Security.salt') . $data['admin_password']), 'group_id' => 1));
                 /*$Site = new Site();
                   $Site->save( array( 'user_id' => $User->getInsertID(), 'domain' => Configure::read( 'CMS.Site.Domain' ) ) );*/
                 App::import('vendor', 'fixtures');
                 $oFixtures = new Fixtures();
                 if ($oFixtures->import($install_files_path . 'fixtures.yml') === true) {
                     $this->flash('Congratulations, you have successfully installed Pagebakery!', '/');
                 } else {
                     $this->Session->setFlash(__('Sorry, there was an error adding initial data', true));
                 }
             }
         } else {
             $this->Session->setFlash('I could not connect to the DataBase. Please check the setup details again.');
         }
     }
     $this->set('DBDrivers', $this->_getDBDrivers());
 }
Exemple #10
0
 function save($data = null, $validate = true, $fieldList = array())
 {
     $cm =& ConnectionManager::getInstance();
     if (property_exists($cm->config, 'joomla')) {
         $ds = $cm->getDataSource('joomla');
     } else {
         $ds = $cm->create('joomla', array('driver' => 'mysql', 'persistent' => false, 'login' => $data['db']['login'], 'password' => $data['db']['password'], 'host' => $data['db']['host'], 'port' => $data['db']['port'], 'prefix' => $data['db']['prefix'], 'database' => $data['db']['database']));
     }
     if ($ds && $ds->connect()) {
         $JosSection = ClassRegistry::init(array('ds' => 'joomla', 'class' => 'J2c.JosSection', 'table' => 'sections', 'type' => 'Model'));
         $count = $JosSection->find('count');
         if ($count > 0) {
             $this->Session->write($this->key, $data);
             return $data;
         }
     }
     unset($cm->config->joomla);
     unset($cm->_connectionsEnum['joomla']);
     return false;
 }
 function admin_test_connection()
 {
     $this->set('title_for_layout', __('Test Connection', true));
     $options = array('ds' => 'joomla', 'type' => 'Model', 'table' => 'content', 'class' => 'J2c.JosContent');
     $cm =& ConnectionManager::getInstance();
     if (property_exists($cm->config, 'joomla')) {
         $count = ClassRegistry::init($options)->find('count');
     } else {
         $count = 0;
     }
     if ($count > 0) {
         $this->Session->setFlash(sprintf(__('Connection seems okay. I can see %d contents from joomla database', true), $count));
         $canMigrate = true;
     } else {
         $this->Session->setFlash(__('I cannot see any contents. Check log files from connection failure or other errors', true));
         $canMigrate = false;
     }
     $migrated = $this->Session->read('J2c.migrated');
     $this->set(compact('canMigrate', 'migrated'));
 }
Exemple #12
0
 /**
  * コンストラクタ
  *
  * @return	void
  * @access	private
  */
 function __construct($id = false, $table = null, $ds = null)
 {
     if ($this->useDbConfig && ($this->name || !empty($id['name']))) {
         // DBの設定がない場合、存在しないURLをリクエストすると、エラーが繰り返されてしまい
         // Cakeの正常なエラーページが表示されないので、設定がある場合のみ親のコンストラクタを呼び出す。
         $cm =& ConnectionManager::getInstance();
         if (isset($cm->config->baser['driver'])) {
             if ($cm->config->baser['driver'] != '') {
                 parent::__construct($id, $table, $ds);
             } elseif ($cm->config->baser['login'] == 'dummy' && $cm->config->baser['password'] == 'dummy' && $cm->config->baser['database'] == 'dummy' && Configure::read('Baser.urlParam') == '') {
                 // データベース設定がインストール段階の状態でトップページへのアクセスの場合、
                 // 初期化ページにリダイレクトする
                 App::import('Controller', 'App');
                 $AppController = new AppController();
                 session_start();
                 $_SESSION['Message']['flash'] = array('message' => 'インストールに失敗している可能性があります。<br />インストールを最初からやり直すにはbaserCMSを初期化してください。', 'layout' => 'default');
                 $AppController->redirect(baseUrl() . 'installations/reset');
             }
         }
     }
 }
Exemple #13
0
 function startup(&$controller)
 {
     $this->controller =& $controller;
     $ConnectionManager = ConnectionManager::getInstance();
     $dbConfigs = array_keys(get_object_vars($ConnectionManager->config));
     if (!in_array('joomla', $dbConfigs)) {
         return true;
     }
     $options = array('ds' => 'joomla', 'type' => 'Model');
     ClassRegistry::init(array('class' => 'J2c.J2cAppModel', 'type' => 'Model', 'table' => false));
     $options = Set::merge($options, array('table' => 'users', 'class' => 'J2c.JosUser'));
     $this->JosUser = ClassRegistry::init($options);
     $this->User = ClassRegistry::init('User');
     $options = Set::merge($options, array('class' => 'J2c.JosCategory', 'table' => 'categories'));
     $this->JosCategory = ClassRegistry::init($options);
     $options = Set::merge($options, array('class' => 'J2c.JosSection', 'table' => 'sections'));
     $this->JosSection = ClassRegistry::init($options);
     $this->Vocabulary = ClassRegistry::init('Vocabulary');
     $this->Term = ClassRegistry::init('Term');
     $this->Taxonomy = ClassRegistry::init('Taxonomy');
     $options = Set::merge($options, array('class' => 'J2c.JosContent', 'table' => 'content'));
     $this->JosContent = ClassRegistry::init($options);
     $this->Node = ClassRegistry::init('Node');
 }
 function _backupDatabase()
 {
     $connection = ConnectionManager::getInstance();
     $database = $connection->config->default;
     $user = $database['login'];
     $pass = $database['password'];
     $host = $database['host'];
     $database = $database['database'];
     $fileDir = ROOT . '/database_backups/';
     $filename = date('Y_m_d_') . $database;
     // path to mysqldump
     $mysqldump = '/usr/bin/mysqldump';
     // Change this to point to the location of your tar
     $tarCmd = '/bin/tar';
     // Dump the database
     $command = "{$mysqldump} -h{$host} -u{$user} -p{$pass} {$database} > " . $fileDir . $filename . '.sql';
     exec($command);
     // Archive the dump
     $command = "{$tarCmd} --directory {$fileDir} -czf " . $fileDir . $filename . '.tar.gz ' . $filename . '.sql';
     exec($command);
     // Delete the dump
     unlink($fileDir . $filename . '.sql');
     return $fileDir . $filename . '.tar.gz';
 }
 /**
  * Returns the file, class name, and parent for the given driver.
  *
  * @return array An indexed array with: filename, classname, and parent
  * @access private
  */
 function __getDriver($config)
 {
     $_this =& ConnectionManager::getInstance();
     if (!isset($config['datasource'])) {
         $config['datasource'] = 'dbo';
     }
     if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
         $filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
         $classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
         $parent = $_this->__getDriver(array('datasource' => $config['datasource']));
     } else {
         $filename = $config['datasource'] . '_source';
         $classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));
         $parent = null;
     }
     return array('filename' => $filename, 'classname' => $classname, 'parent' => $parent);
 }
Exemple #16
0
 /**
  * Get Connection
  *
  * @return  rdbms.DBConnection
  */
 public function getConnection()
 {
     if (!isset($this->conn)) {
         $this->conn = ConnectionManager::getInstance()->getByHost($this->connection, 0);
     }
     return $this->conn;
 }
 function _isDbConnected()
 {
     $db = ConnectionManager::getInstance();
     @($connected = $db->getDataSource($this->useDbConfig));
     if (!$connected->isConnected()) {
         return false;
     } else {
         return true;
     }
 }
 /**
  * Dynamically creates a DataSource object at runtime, with the given name and settings
  *
  * @param string $name The DataSource name
  * @param array $config The DataSource configuration settings
  * @return object A reference to the DataSource object, or null if creation failed
  * @access public
  * @static
  */
 function &create($name = '', $config = array())
 {
     $_this =& ConnectionManager::getInstance();
     if (empty($name) || empty($config) || array_key_exists($name, $_this->_connectionsEnum)) {
         $null = null;
         return $null;
     }
     $_this->config->{$name} = $config;
     $_this->_connectionsEnum[$name] = $_this->__getDriver($config);
     $return =& $_this->getDataSource($name);
     return $return;
 }
 public static function registerConnection()
 {
     ConnectionManager::getInstance()->register(new MySQLConnection(new DSN('mysql://localhost:3306/')), 'jobs');
 }
Exemple #20
0
 /**
  * Creates the scriptlet instance for the given URL and runs it
  *
  * @param   string url default '/'
  */
 public function run($url = '/')
 {
     // Determine which scriptlet should be run
     $application = $this->applicationAt($url);
     // Determine debug level
     $flags = $application->getDebug();
     // Initializer logger, properties and connections to property base,
     // defaulting to the same directory the web.ini resides in
     $pm = PropertyManager::getInstance();
     foreach (explode('|', $application->getConfig()) as $element) {
         $expanded = $this->expand($element);
         if (0 == strncmp('res://', $expanded, 6)) {
             $pm->appendSource(new ResourcePropertySource($expanded));
         } else {
             $pm->appendSource(new FilesystemPropertySource($expanded));
         }
     }
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     $cm = ConnectionManager::getInstance();
     $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (NULL === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname($_SERVER['SERVER_NAME']);
         $context->setRunner($this->getClassName());
         $context->setInstance($application->getScriptlet());
         $context->setResource($url);
         $context->setParams($_SERVER['QUERY_STRING']);
     }
     // Set environment variables
     foreach ($application->getEnvironment() as $key => $value) {
         $_SERVER[$key] = $this->expand($value);
     }
     // Instantiate and initialize
     $cat = $l->getCategory('scriptlet');
     $instance = NULL;
     $e = NULL;
     try {
         $class = XPClass::forName($application->getScriptlet());
         if (!$class->hasConstructor()) {
             $instance = $class->newInstance();
         } else {
             $args = array();
             foreach ($application->getArguments() as $arg) {
                 $args[] = $this->expand($arg);
             }
             $instance = $class->getConstructor()->newInstance($args);
         }
         if ($flags & WebDebug::TRACE && $instance instanceof Traceable) {
             $instance->setTrace($cat);
         }
         $instance->init();
         // Service
         $response = $instance->process();
     } catch (ScriptletException $e) {
         $cat->error($e);
         // TODO: Instead of checking for a certain method, this should
         // check if the scriptlet class implements a certain interface
         if (method_exists($instance, 'fail')) {
             $response = $instance->fail($e);
         } else {
             $response = $this->fail($e, $e->getStatus(), $flags & WebDebug::STACKTRACE);
         }
     } catch (SystemExit $e) {
         if (0 === $e->getCode()) {
             $response = new HttpScriptletResponse();
             $response->setStatus(HttpConstants::STATUS_OK);
             if ($message = $e->getMessage()) {
                 $response->setContent($message);
             }
         } else {
             $cat->error($e);
             $response = $this->fail($e, HttpConstants::STATUS_INTERNAL_SERVER_ERROR, FALSE);
         }
     } catch (Throwable $e) {
         $cat->error($e);
         // Here, we might not have a scriptlet
         $response = $this->fail($e, HttpConstants::STATUS_PRECONDITION_FAILED, $flags & WebDebug::STACKTRACE);
     }
     // Send output
     $response->isCommitted() || $response->flush();
     $response->sendContent();
     // Call scriptlet's finalizer
     $instance && $instance->finalize();
     // Debugging
     if ($flags & WebDebug::XML && isset($response->document)) {
         flush();
         echo '<xmp>', $response->document->getDeclaration() . "\n" . $response->document->getSource(0), '</xmp>';
     }
     if ($flags & WebDebug::ERRORS) {
         flush();
         echo '<xmp>', $e ? $e->toString() : '', xp::stringOf(xp::$errors), '</xmp>';
     }
 }
Exemple #21
0
 /**
  * Main method
  *
  * @param   util.cmd.ParamString params
  * @return  int
  */
 public function run(ParamString $params)
 {
     // No arguments given - show our own usage
     if ($params->count < 1) {
         self::$err->writeLine(self::textOf(XPClass::forName(xp::nameOf(__CLASS__))->getComment()));
         return 1;
     }
     // Configure properties
     $pm = PropertyManager::getInstance();
     // Separate runner options from class options
     for ($offset = 0, $i = 0; $i < $params->count; $i++) {
         switch ($params->list[$i]) {
             case '-c':
                 if (0 == strncmp('res://', $params->list[$i + 1], 6)) {
                     $pm->appendSource(new ResourcePropertySource(substr($params->list[$i + 1], 6)));
                 } else {
                     $pm->appendSource(new FilesystemPropertySource($params->list[$i + 1]));
                 }
                 $offset += 2;
                 $i++;
                 break;
             case '-cp':
                 ClassLoader::registerPath($params->list[$i + 1], NULL);
                 $offset += 2;
                 $i++;
                 break;
             case '-v':
                 $this->verbose = TRUE;
                 $offset += 1;
                 $i++;
                 break;
             default:
                 break 2;
         }
     }
     // Sanity check
     if (!$params->exists($offset)) {
         self::$err->writeLine('*** Missing classname');
         return 1;
     }
     // Use default path for PropertyManager if no sources set
     if (!$pm->getSources()) {
         $pm->configure(self::DEFAULT_CONFIG_PATH);
     }
     unset($params->list[-1]);
     $classname = $params->value($offset);
     $classparams = new ParamString(array_slice($params->list, $offset + 1));
     // Class file or class name
     if (strstr($classname, xp::CLASS_FILE_EXT)) {
         $file = new File($classname);
         if (!$file->exists()) {
             self::$err->writeLine('*** Cannot load class from non-existant file ', $classname);
             return 1;
         }
         $uri = $file->getURI();
         $path = dirname($uri);
         $paths = array_flip(array_map('realpath', xp::$classpath));
         $class = NULL;
         while (FALSE !== ($pos = strrpos($path, DIRECTORY_SEPARATOR))) {
             if (isset($paths[$path])) {
                 $class = XPClass::forName(strtr(substr($uri, strlen($path) + 1, -10), DIRECTORY_SEPARATOR, '.'));
                 break;
             }
             $path = substr($path, 0, $pos);
         }
         if (!$class) {
             self::$err->writeLine('*** Cannot load class from ', $file);
             return 1;
         }
     } else {
         try {
             $class = XPClass::forName($classname);
         } catch (ClassNotFoundException $e) {
             self::$err->writeLine('*** ', $this->verbose ? $e : $e->getMessage());
             return 1;
         }
     }
     // Check whether class is runnable
     if (!$class->isSubclassOf('lang.Runnable')) {
         self::$err->writeLine('*** ', $class->getName(), ' is not runnable');
         return 1;
     }
     // Usage
     if ($classparams->exists('help', '?')) {
         self::showUsage($class);
         return 0;
     }
     // Load, instantiate and initialize
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     $cm = ConnectionManager::getInstance();
     $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (NULL === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname(System::getProperty('host.name'));
         $context->setRunner($this->getClassName());
         $context->setInstance($class->getName());
         $context->setResource(NULL);
         $context->setParams($params->string);
     }
     $instance = $class->newInstance();
     $instance->in = self::$in;
     $instance->out = self::$out;
     $instance->err = self::$err;
     $methods = $class->getMethods();
     // Injection
     foreach ($methods as $method) {
         if (!$method->hasAnnotation('inject')) {
             continue;
         }
         $inject = $method->getAnnotation('inject');
         if (isset($inject['type'])) {
             $type = $inject['type'];
         } else {
             if ($restriction = $method->getParameter(0)->getTypeRestriction()) {
                 $type = $restriction->getName();
             } else {
                 $type = $method->getParameter(0)->getType()->getName();
             }
         }
         try {
             switch ($type) {
                 case 'rdbms.DBConnection':
                     $args = array($cm->getByHost($inject['name'], 0));
                     break;
                 case 'util.Properties':
                     $p = $pm->getProperties($inject['name']);
                     // If a PropertyAccess is retrieved which is not a util.Properties,
                     // then, for BC sake, convert it into a util.Properties
                     if ($p instanceof PropertyAccess && !$p instanceof Properties) {
                         $convert = Properties::fromString('');
                         $section = $p->getFirstSection();
                         while ($section) {
                             // HACK: Properties::writeSection() would first attempts to
                             // read the whole file, we cannot make use of it.
                             $convert->_data[$section] = $p->readSection($section);
                             $section = $p->getNextSection();
                         }
                         $args = array($convert);
                     } else {
                         $args = array($p);
                     }
                     break;
                 case 'util.log.LogCategory':
                     $args = array($l->getCategory($inject['name']));
                     break;
                 default:
                     self::$err->writeLine('*** Unknown injection type "' . $type . '" at method "' . $method->getName() . '"');
                     return 2;
             }
             $method->invoke($instance, $args);
         } catch (TargetInvocationException $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->getCause()->compoundMessage());
             return 2;
         } catch (Throwable $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->compoundMessage());
             return 2;
         }
     }
     // Arguments
     foreach ($methods as $method) {
         if ($method->hasAnnotation('args')) {
             // Pass all arguments
             if (!$method->hasAnnotation('args', 'select')) {
                 $begin = 0;
                 $end = $classparams->count;
                 $pass = array_slice($classparams->list, 0, $end);
             } else {
                 $pass = array();
                 foreach (preg_split('/, ?/', $method->getAnnotation('args', 'select')) as $def) {
                     if (is_numeric($def) || '-' == $def[0]) {
                         $pass[] = $classparams->value((int) $def);
                     } else {
                         sscanf($def, '[%d..%d]', $begin, $end);
                         isset($begin) || ($begin = 0);
                         isset($end) || ($end = $classparams->count - 1);
                         while ($begin <= $end) {
                             $pass[] = $classparams->value($begin++);
                         }
                     }
                 }
             }
             try {
                 $method->invoke($instance, array($pass));
             } catch (Throwable $e) {
                 self::$err->writeLine('*** Error for arguments ' . $begin . '..' . $end . ': ', $this->verbose ? $e : $e->getMessage());
                 return 2;
             }
         } else {
             if ($method->hasAnnotation('arg')) {
                 // Pass arguments
                 $arg = $method->getAnnotation('arg');
                 if (isset($arg['position'])) {
                     $name = '#' . ($arg['position'] + 1);
                     $select = intval($arg['position']);
                     $short = NULL;
                 } else {
                     if (isset($arg['name'])) {
                         $name = $select = $arg['name'];
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     } else {
                         $name = $select = strtolower(preg_replace('/^set/', '', $method->getName()));
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     }
                 }
                 if (0 == $method->numParameters()) {
                     if (!$classparams->exists($select, $short)) {
                         continue;
                     }
                     $args = array();
                 } else {
                     if (!$classparams->exists($select, $short)) {
                         list($first, ) = $method->getParameters();
                         if (!$first->isOptional()) {
                             self::$err->writeLine('*** Argument ' . $name . ' does not exist!');
                             return 2;
                         }
                         $args = array();
                     } else {
                         $args = array($classparams->value($select, $short));
                     }
                 }
                 try {
                     $method->invoke($instance, $args);
                 } catch (TargetInvocationException $e) {
                     self::$err->writeLine('*** Error for argument ' . $name . ': ', $this->verbose ? $e->getCause() : $e->getCause()->compoundMessage());
                     return 2;
                 }
             }
         }
     }
     try {
         $instance->run();
     } catch (Throwable $t) {
         self::$err->writeLine('*** ', $t->toString());
         return 70;
         // EX_SOFTWARE according to sysexits.h
     }
     return 0;
 }
 /**
  * Fetch DB connection resource
  *
  * @param   string name
  * @return  rdbms.DBConnection
  */
 function getDBConnection($name)
 {
     return ConnectionManager::getInstance()->getByHost($name, 0);
 }
 /**
  * beforeFilter
  *
  * @return void
  * @access public
  */
 function beforeFilter()
 {
     /* インストール状態判別 */
     if (file_exists(CONFIGS . 'database.php')) {
         $db = ConnectionManager::getInstance();
         if ($db->config->baser['driver'] != '') {
             $installed = 'complete';
         } else {
             $installed = 'half';
         }
     } else {
         $installed = 'yet';
     }
     switch ($this->action) {
         case 'alert':
             break;
         case 'reset':
             if (Configure::read('debug') != -1) {
                 $this->notFound();
             }
             break;
         default:
             if ($installed == 'complete') {
                 $this->notFound();
             } else {
                 if (Configure::read('debug') == 0) {
                     $this->redirect(array('action' => 'alert'));
                 }
             }
             break;
     }
     if (strpos($this->webroot, 'webroot') === false) {
         $this->webroot = DS;
     }
     $this->theme = null;
     $this->Security->validatePost = false;
 }
Exemple #24
0
 * @link			http://basercms.net BaserCMS Project
 * @package			baser.config
 * @since			Baser v 0.1.0
 * @version			$Revision$
 * @modifiedby		$LastChangedBy$
 * @lastmodified	$Date$
 * @license			http://basercms.net/license/index.html
 */
/**
 * vendors内の静的ファイルの読み込みの場合はスキップ
 */
if (Configure::read('Baser.Asset')) {
    return;
}
if (file_exists(CONFIGS . 'database.php')) {
    $cn = ConnectionManager::getInstance();
}
if (!empty($cn->config->baser['driver'])) {
    $parameter = getUrlParamFromEnv();
    Configure::write('Baser.urlParam', $parameter);
    // requestAction の場合、bootstrapが実行されないので、urlParamを書き換える
    $parameter = Configure::read('Baser.urlParam');
    $agentOn = Configure::read('AgentPrefix.on');
    $agentAlias = Configure::read('AgentPrefix.currentAlias');
    $agentPrefix = Configure::read('AgentPrefix.currentPrefix');
    /**
     * 管理画面トップページ
     */
    Router::connect('admin', array('admin' => true, 'controller' => 'dashboard', 'action' => 'index'));
    /**
     * 追加プレフィックス
 /**
  * Step 5: 設定ファイルの生成
  * データベース設定ファイル[database.php]
  * インストールファイル[install.php]
  * 
  * @return void
  * @access public
  */
 function step5()
 {
     $this->pageTitle = 'baserCMSのインストール完了!';
     $db = ConnectionManager::getInstance();
     if ($db->config->baser['driver'] == '') {
         // データベース設定を書き込む
         $this->_writeDatabaseConfig($this->_readDbSettingFromSession());
         // DB設定ファイルを再読み込みする為リダイレクトする
         $this->redirect('step5');
     } elseif (isInstalled()) {
         return;
     }
     $message = '';
     // インストールファイルを生成する
     if (!$this->_createInstallFile()) {
         if ($message) {
             $message .= '<br />';
         }
         $message .= '/app/config/install.php インストール設定ファイルの設定ができませんでした。パーミションの確認をしてください。';
     }
     // tmp フォルダを作成する
     checkTmpFolders();
     // ブログの投稿日を更新
     $this->_updateEntryDate();
     // プラグインのステータスを更新
     $this->_updatePluginStatus();
     // ログイン
     $this->_login();
     // テーマを配置する
     $this->BaserManager->deployTheme();
     $this->BaserManager->deployTheme('skelton');
     // pagesファイルを生成する
     $this->_createPages();
     ClassRegistry::removeObject('View');
     // デバッグモードを0に変更
     $this->writeDebug(0);
     if ($message) {
         $this->setFlash($message);
     }
 }
 /**
  * Empties connection manager pool
  *
  */
 public function setUp()
 {
     ConnectionManager::getInstance()->pool = array();
 }
 /**
  * Write this object to the database
  *
  * @return  bool success
  * @throws  rdbms.SQLException in case an error occurs
  * @throws  lang.IllegalAccessException in case there is no suitable database connection available
  */
 public function insert()
 {
     $cm = ConnectionManager::getInstance();
     $db = $cm->getByHost('nagios', 0);
     $db->insert('nagios.hoststatus (%c)', $this->_inserted($db));
     return TRUE;
 }
 /**
  * setUp method
  *
  * @access public
  * @return void
  */
 function setUp()
 {
     $this->ConnectionManager =& ConnectionManager::getInstance();
 }
 /**
  * @return \Doctrine\Common\Cache\Cache
  */
 public function getReflectionCache()
 {
     return ConnectionManager::getInstance()->get()->getReflectionCache();
 }