Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Cleanup database files and add SQLite support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Nov 3, 2014
1 parent 6c978ee commit f48bec7
Show file tree
Hide file tree
Showing 234 changed files with 5,388 additions and 3,733 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ install:
- composer install

before_script:
- cp tests/travis/mysql.ini tests/configs/mysql.ini && cp tests/travis/pgsql.ini tests/configs/pgsql.ini
- cp tests/travis/mysql.ini tests/configs/mysql.ini
- cp tests/travis/pgsql.ini tests/configs/pgsql.ini
- cp tests/travis/sqlite.ini tests/configs/sqlite.ini
- mysql -u root -e 'create database midas_test;'
- psql -U postgres -c 'create database midas_test;'
- touch midas_test.db

script:
- mkdir _test && cd _test
Expand Down
34 changes: 26 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,27 @@
cmake_minimum_required(VERSION 2.8)
project(Midas)

find_program(PHP "php" CACHE STRING "PHP executable.")
find_program(PHP "php" CACHE STRING "PHP executable")
if(NOT PHP)
message(FATAL_ERROR "Please set the PHP executable")
message(FATAL_ERROR "Please set the path to the PHP executable")
endif()

find_file(COMPOSER_LOCK "composer.lock" PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
if(NOT COMPOSER_LOCK)
find_file(COMPOSER_PHAR "composer.phar")
if(NOT COMPOSER_PHAR)
message(FATAL_ERROR "Please set the path to composer.phar")
endif()
execute_process(
COMMAND ${PHP} ${COMPOSER_PHAR} install
RESULT_VARIABLE COMPOSER_INSTALL_RESULT
OUTPUT_VARIABLE COMPOSER_INSTALL_OUTPUT
ERROR_VARIABLE COMPOSER_INSTALL_ERROR)
if(NOT COMPOSER_INSTALL_RESULT EQUAL 0)
message(STATUS "Composer install output: ${COMPOSER_INSTALL_OUTPUT}")
message(FATAL_ERROR "Composer install error: ${COMPOSER_INSTALL_ERROR}")
endif()
message(STATUS "Composer install is complete")
endif()

#-----------------------------------------------------------------------------
Expand All @@ -33,12 +51,12 @@ endif()
message(STATUS "Setting up database(s) for testing, please wait...")
execute_process(
COMMAND ${PHP} ${CMAKE_CURRENT_SOURCE_DIR}/tests/DatabaseSetup.php
RESULT_VARIABLE databaseSetup_RESULT
OUTPUT_VARIABLE databaseSetup_OUT
ERROR_VARIABLE databaseSetup_ERR)
if(NOT databaseSetup_RESULT EQUAL 0)
message(STATUS "Database setup output: ${databaseSetup_OUT}")
message(FATAL_ERROR "Database setup error: ${databaseSetup_ERR}")
RESULT_VARIABLE DATABASE_SETUP_RESULT
OUTPUT_VARIABLE DATABASE_SETUP_OUTPUT
ERROR_VARIABLE DATABASE_SETUP_ERROR)
if(NOT DATABASE_SETUP_RESULT EQUAL 0)
message(STATUS "Database setup output: ${DATABASE_SETUP_OUTPUT}")
message(FATAL_ERROR "Database setup error: ${DATABASE_SETUP_ERROR}")
endif()
message(STATUS "Database setup is complete")

Expand Down
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ skip_files:
- ^(.*/)?(\.coveralls.yml|\.project|\.travis.yml|\.zfproject\.xml|composer\.json|COPYRIGHT|CTestConfig\.cmake|LICENSE|README\.md|Vagrantfile)$
- ^(.*/)?core/configs/.*\.local\.ini$
- ^(.*/)?(\.git|\.idea|\.vagrant|data|log|nbproject|provisioning|tests|tmp|utils)/.*
- ^(.*/)?(core|modules/.*)/(database/pgsql|tests)/.*
- ^(.*/)?(core|modules/.*)/(database/pgsql|sqlite|tests)/.*
- ^(.*/)?library/CMake/.*
- ^(.*/)?modules/(batchmake|dicom.*|example|metadataextractor|pvw|remoteprocessing|solr|statistics|thumbnailcreator|visualize)/.*
4 changes: 2 additions & 2 deletions core/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function preDispatch()
}
$errorlogModel = MidasLoader::loadModel('Errorlog');
$count = $errorlogModel->countSince(
date("Y-m-d H:i:s", strtotime('-24 hour')),
date('Y-m-d H:i:s', strtotime('-24 hour')),
array(MIDAS_PRIORITY_CRITICAL, MIDAS_PRIORITY_WARNING)
);

Expand Down Expand Up @@ -357,7 +357,7 @@ private function _logRequest()
{
$fc = Zend_Controller_Front::getInstance();

$entry = date("Y-m-d H:i:s")."\n";
$entry = date('Y-m-d H:i:s')."\n";
if (isset($_SERVER['REMOTE_ADDR'])) {
$entry .= 'IP='.$_SERVER['REMOTE_ADDR']."\n";
}
Expand Down
36 changes: 25 additions & 11 deletions core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,37 @@ protected function _initConfig()
} else {
$driverOptions = $configDatabase->database->params->driver_options->toArray();
}
$driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
$params = array(
'dbname' => $configDatabase->database->params->dbname,
'username' => $configDatabase->database->params->username,
'password' => $configDatabase->database->params->password,
'driver_options' => $driverOptions,
);
if (empty($configDatabase->database->params->unix_socket)) {
$params['host'] = $configDatabase->database->params->host;
$params['port'] = $configDatabase->database->params->port;

if ($configDatabase->database->adapter == 'PDO_SQLITE') {
$params = array(
'dbname' => $configDatabase->database->params->dbname,
'driver_options' => $driverOptions,
);
} else {
$params['unix_socket'] = $configDatabase->database->params->unix_socket;
if ($configDatabase->database->adapter == 'PDO_MYSQL') {
$driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
}

$params = array(
'dbname' => $configDatabase->database->params->dbname,
'username' => $configDatabase->database->params->username,
'password' => $configDatabase->database->params->password,
'driver_options' => $driverOptions,
);

if (empty($configDatabase->database->params->unix_socket)) {
$params['host'] = $configDatabase->database->params->host;
$params['port'] = $configDatabase->database->params->port;
} else {
$params['unix_socket'] = $configDatabase->database->params->unix_socket;
}
}

if ($configGlobal->environment == 'production') {
Zend_Loader::loadClass('ProductionDbProfiler', BASE_PATH.'/core/models/profiler');
$params['profiler'] = new ProductionDbProfiler();
}

$db = Zend_Db::factory($configDatabase->database->adapter, $params);
$db->getProfiler()->setEnabled(true);
Zend_Db_Table::setDefaultAdapter($db);
Expand Down
53 changes: 29 additions & 24 deletions core/configs/database.ini
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.

[production]
database.profiler = 0
database.adapter = PDO_MYSQL
database.params.host = localhost
database.params.port = 3306
database.params.unix_socket =
database.params.dbname = midas
database.params.username = root
database.params.password =
database.adapter = "PDO_MYSQL"
database.params.host = "localhost"
database.params.port = "3306"
database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
database.profiler = "0"
version = ""

[development]
database.profiler = 1
database.adapter = PDO_MYSQL
database.params.host = localhost
database.params.port = 3306
database.params.unix_socket =
database.params.dbname = midas
database.params.username = root
database.params.password =
database.adapter = "PDO_MYSQL"
database.params.host = "localhost"
database.params.port = "3306"
database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
database.profiler = "1"
version = ""

[testing]
database.profiler = 1
database.adapter = PDO_MYSQL
database.params.host = localhost
database.params.port = 3306
database.params.unix_socket =
database.params.dbname = midas_test
database.params.username = root
database.params.password =
database.adapter = "PDO_MYSQL"
database.params.host = "localhost"
database.params.port = "3306"
database.params.unix_socket = ""
database.params.dbname = "midas_test"
database.params.username = "root"
database.params.password = ""
database.profiler = "1"
version = ""
8 changes: 4 additions & 4 deletions core/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ public function showlogAction()
$limit = $this->getParam('limit');
$offset = $this->getParam('offset');
if (!isset($start) || empty($start)) {
$start = date("Y-m-d H:i:s", strtotime('-24 hour'));
$start = date('Y-m-d H:i:s', strtotime('-24 hour'));
} else {
$start = date("Y-m-d H:i:s", strtotime($start));
$start = date('Y-m-d H:i:s', strtotime($start));
}
if (!isset($end) || empty($end)) {
$end = date("Y-m-d H:i:s");
$end = date('Y-m-d H:i:s');
} else {
$end = date("Y-m-d H:i:s", strtotime($end));
$end = date('Y-m-d H:i:s', strtotime($end));
}
if (!isset($module) || empty($module)) {
$module = 'all';
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private function _recursiveParseDirectory($path, $currentdir)
$child = new FolderDao();
$child->setName($fileInfo->getFilename());
$child->setParentId($currentdir->getFolderId());
$child->setDateCreation(date("Y-m-d H:i:s"));
$child->setDateCreation(date('Y-m-d H:i:s'));
$child->setDescription('');
$this->Folder->save($child);
$this->Folderpolicyuser->createPolicy($this->userSession->Dao, $child, MIDAS_POLICY_ADMIN);
Expand Down
83 changes: 49 additions & 34 deletions core/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ public function step2Action()
}
$this->view->header = 'Step 2: Database Configuration';

$databases = array('mysql', 'pgsql');
$databases = array('mysql', 'pgsql', 'sqlite');
$this->view->databaseType = array();
foreach ($databases as $database) {
if (!extension_loaded('pdo_'.$database) || !file_exists(BASE_PATH.'/core/database/'.$database)
) {
unset($database);
} else {
$form = $this->Form->Install->createDBForm();
$host = $form->getElement('host');
$port = $form->getElement('port');
$username = $form->getElement('username');
switch ($database) {
Expand All @@ -86,6 +87,11 @@ public function step2Action()
$port->setValue('5432');
$username->setValue('postgres');
break;
case 'sqlite':
$host->setValue('');
$port->setValue('');
$username->setValue('');
break;
default:
break;
}
Expand Down Expand Up @@ -144,16 +150,18 @@ public function step2Action()
$driverOptions = array();
$params = array(
'dbname' => $form->getValue('dbname'),
'username' => $form->getValue('username'),
'password' => $form->getValue('password'),
'driver_options' => $driverOptions,
);
$unixsocket = $form->getValue('unix_socket');
if ($unixsocket) {
$params['unix_socket'] = $unixsocket;
} else {
$params['host'] = $form->getValue('host');
$params['port'] = $form->getValue('port');
if ($dbtype != 'PDO_SQLITE') {
$params['username'] = $form->getValue('username');
$params['password'] = $form->getValue('password');
$unixsocket = $form->getValue('unix_socket');
if ($unixsocket) {
$params['unix_socket'] = $unixsocket;
} else {
$params['host'] = $form->getValue('host');
$params['port'] = $form->getValue('port');
}
}

$db = Zend_Db::factory($dbtype, $params);
Expand All @@ -176,9 +184,11 @@ public function step2Action()
$configGlobal = new Zend_Config_Ini(LOCAL_CONFIGS_PATH.'/application.local.ini', 'global');
Zend_Registry::set('configGlobal', $configGlobal);

$configDatabase = new Zend_Config_Ini(LOCAL_CONFIGS_PATH.'/database.local.ini', $configGlobal->environment);
Zend_Registry::set('configDatabase', $configDatabase);

require_once BASE_PATH.'/core/controllers/components/UpgradeComponent.php';
$upgradeComponent = new UpgradeComponent();
$db = Zend_Registry::get('dbAdapter');

$upgradeComponent->initUpgrade('core', $db, $dbtype);
$upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile)));
Expand Down Expand Up @@ -268,31 +278,36 @@ public function testconnectionAction()
$this->requireAjaxRequest();
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
try {
$driverOptions = array();
$params = array(
'dbname' => $this->getParam('dbname'),
'username' => $this->getParam('username'),
'password' => $this->getParam('password'),
'driver_options' => $driverOptions,
);
$unixsocket = $this->getParam('unix_socket');
if ($unixsocket) {
$params['unix_socket'] = $this->getParam('unix_socket');
} else {
$params['host'] = $this->getParam('host');
$params['port'] = $this->getParam('port');
}
$db = Zend_Db::factory('PDO_'.strtoupper($this->getParam('type')), $params);
$tables = $db->listTables();
if (count($tables) > 0) {
$return = array(false, 'The database is not empty');
} else {
$return = array(true, 'The database is reachable');
$dbtype = 'PDO_'.strtoupper($this->getParam('type'));
if ($dbtype === 'PDO_SQLITE') {
$return = array(true, 'The database is reachable');
} else {
try {
$driverOptions = array();
$params = array(
'dbname' => $this->getParam('dbname'),
'username' => $this->getParam('username'),
'password' => $this->getParam('password'),
'driver_options' => $driverOptions,
);
$unixsocket = $this->getParam('unix_socket');
if ($unixsocket) {
$params['unix_socket'] = $this->getParam('unix_socket');
} else {
$params['host'] = $this->getParam('host');
$params['port'] = $this->getParam('port');
}
$db = Zend_Db::factory('PDO_'.strtoupper($this->getParam('type')), $params);
$tables = $db->listTables();
if (count($tables) > 0) {
$return = array(false, 'The database is not empty');
} else {
$return = array(true, 'The database is reachable');
}
$db->closeConnection();
} catch (Zend_Exception $exception) {
$return = array(false, 'Could not connect to the database');
}
$db->closeConnection();
} catch (Zend_Exception $exception) {
$return = array(false, 'Could not connect to the database');
}
echo JsonComponent::encode($return);
}
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/components/ApisystemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function uploadGeneratetoken($args)
$revision = new ItemRevisionDao();
$revision->setChanges('Initial revision');
$revision->setUser_id($userDao->getKey());
$revision->setDate(date("Y-m-d H:i:s"));
$revision->setDate(date('Y-m-d H:i:s'));
$revision->setLicenseId(null);
$itemModel->addRevision($item, $revision);
}
Expand Down
4 changes: 2 additions & 2 deletions core/controllers/components/NotifyErrorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getFatalErrorMessage($e)
$message .= "Request type: ".$this->_server['HTTP_X_REQUESTED_WITH']."\n";
}

$message .= "Server time: ".date("Y-m-d H:i:s")."\n";
$message .= "Server time: ".date('Y-m-d H:i:s')."\n";

if (!empty($this->_server['HTTP_REFERER'])) {
$message .= "Referer: ".$this->_server['HTTP_REFERER']."\n";
Expand Down Expand Up @@ -217,7 +217,7 @@ public function getFullErrorMessage()
$message .= "Request type: ".$this->_server['HTTP_X_REQUESTED_WITH']."\n";
}

$message .= "Server time: ".date("Y-m-d H:i:s")."\n";
$message .= "Server time: ".date('Y-m-d H:i:s')."\n";
$message .= "RequestURI: ".$this->_error->request->getRequestUri()."\n";

if (!empty($this->_server['HTTP_REFERER'])) {
Expand Down
Loading

0 comments on commit f48bec7

Please sign in to comment.