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

Commit f48bec7

Browse files
author
Jamie Snape
committed
Cleanup database files and add SQLite support
1 parent 6c978ee commit f48bec7

File tree

234 files changed

+5388
-3733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+5388
-3733
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ install:
3232
- composer install
3333

3434
before_script:
35-
- cp tests/travis/mysql.ini tests/configs/mysql.ini && cp tests/travis/pgsql.ini tests/configs/pgsql.ini
35+
- cp tests/travis/mysql.ini tests/configs/mysql.ini
36+
- cp tests/travis/pgsql.ini tests/configs/pgsql.ini
37+
- cp tests/travis/sqlite.ini tests/configs/sqlite.ini
3638
- mysql -u root -e 'create database midas_test;'
3739
- psql -U postgres -c 'create database midas_test;'
40+
- touch midas_test.db
3841

3942
script:
4043
- mkdir _test && cd _test

CMakeLists.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,27 @@
2020
cmake_minimum_required(VERSION 2.8)
2121
project(Midas)
2222

23-
find_program(PHP "php" CACHE STRING "PHP executable.")
23+
find_program(PHP "php" CACHE STRING "PHP executable")
2424
if(NOT PHP)
25-
message(FATAL_ERROR "Please set the PHP executable")
25+
message(FATAL_ERROR "Please set the path to the PHP executable")
26+
endif()
27+
28+
find_file(COMPOSER_LOCK "composer.lock" PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
29+
if(NOT COMPOSER_LOCK)
30+
find_file(COMPOSER_PHAR "composer.phar")
31+
if(NOT COMPOSER_PHAR)
32+
message(FATAL_ERROR "Please set the path to composer.phar")
33+
endif()
34+
execute_process(
35+
COMMAND ${PHP} ${COMPOSER_PHAR} install
36+
RESULT_VARIABLE COMPOSER_INSTALL_RESULT
37+
OUTPUT_VARIABLE COMPOSER_INSTALL_OUTPUT
38+
ERROR_VARIABLE COMPOSER_INSTALL_ERROR)
39+
if(NOT COMPOSER_INSTALL_RESULT EQUAL 0)
40+
message(STATUS "Composer install output: ${COMPOSER_INSTALL_OUTPUT}")
41+
message(FATAL_ERROR "Composer install error: ${COMPOSER_INSTALL_ERROR}")
42+
endif()
43+
message(STATUS "Composer install is complete")
2644
endif()
2745

2846
#-----------------------------------------------------------------------------
@@ -33,12 +51,12 @@ endif()
3351
message(STATUS "Setting up database(s) for testing, please wait...")
3452
execute_process(
3553
COMMAND ${PHP} ${CMAKE_CURRENT_SOURCE_DIR}/tests/DatabaseSetup.php
36-
RESULT_VARIABLE databaseSetup_RESULT
37-
OUTPUT_VARIABLE databaseSetup_OUT
38-
ERROR_VARIABLE databaseSetup_ERR)
39-
if(NOT databaseSetup_RESULT EQUAL 0)
40-
message(STATUS "Database setup output: ${databaseSetup_OUT}")
41-
message(FATAL_ERROR "Database setup error: ${databaseSetup_ERR}")
54+
RESULT_VARIABLE DATABASE_SETUP_RESULT
55+
OUTPUT_VARIABLE DATABASE_SETUP_OUTPUT
56+
ERROR_VARIABLE DATABASE_SETUP_ERROR)
57+
if(NOT DATABASE_SETUP_RESULT EQUAL 0)
58+
message(STATUS "Database setup output: ${DATABASE_SETUP_OUTPUT}")
59+
message(FATAL_ERROR "Database setup error: ${DATABASE_SETUP_ERROR}")
4260
endif()
4361
message(STATUS "Database setup is complete")
4462

app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ skip_files:
5050
- ^(.*/)?(\.coveralls.yml|\.project|\.travis.yml|\.zfproject\.xml|composer\.json|COPYRIGHT|CTestConfig\.cmake|LICENSE|README\.md|Vagrantfile)$
5151
- ^(.*/)?core/configs/.*\.local\.ini$
5252
- ^(.*/)?(\.git|\.idea|\.vagrant|data|log|nbproject|provisioning|tests|tmp|utils)/.*
53-
- ^(.*/)?(core|modules/.*)/(database/pgsql|tests)/.*
53+
- ^(.*/)?(core|modules/.*)/(database/pgsql|sqlite|tests)/.*
5454
- ^(.*/)?library/CMake/.*
5555
- ^(.*/)?modules/(batchmake|dicom.*|example|metadataextractor|pvw|remoteprocessing|solr|statistics|thumbnailcreator|visualize)/.*

core/AppController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function preDispatch()
142142
}
143143
$errorlogModel = MidasLoader::loadModel('Errorlog');
144144
$count = $errorlogModel->countSince(
145-
date("Y-m-d H:i:s", strtotime('-24 hour')),
145+
date('Y-m-d H:i:s', strtotime('-24 hour')),
146146
array(MIDAS_PRIORITY_CRITICAL, MIDAS_PRIORITY_WARNING)
147147
);
148148

@@ -357,7 +357,7 @@ private function _logRequest()
357357
{
358358
$fc = Zend_Controller_Front::getInstance();
359359

360-
$entry = date("Y-m-d H:i:s")."\n";
360+
$entry = date('Y-m-d H:i:s')."\n";
361361
if (isset($_SERVER['REMOTE_ADDR'])) {
362362
$entry .= 'IP='.$_SERVER['REMOTE_ADDR']."\n";
363363
}

core/Bootstrap.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,37 @@ protected function _initConfig()
7373
} else {
7474
$driverOptions = $configDatabase->database->params->driver_options->toArray();
7575
}
76-
$driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
77-
$params = array(
78-
'dbname' => $configDatabase->database->params->dbname,
79-
'username' => $configDatabase->database->params->username,
80-
'password' => $configDatabase->database->params->password,
81-
'driver_options' => $driverOptions,
82-
);
83-
if (empty($configDatabase->database->params->unix_socket)) {
84-
$params['host'] = $configDatabase->database->params->host;
85-
$params['port'] = $configDatabase->database->params->port;
76+
77+
if ($configDatabase->database->adapter == 'PDO_SQLITE') {
78+
$params = array(
79+
'dbname' => $configDatabase->database->params->dbname,
80+
'driver_options' => $driverOptions,
81+
);
8682
} else {
87-
$params['unix_socket'] = $configDatabase->database->params->unix_socket;
83+
if ($configDatabase->database->adapter == 'PDO_MYSQL') {
84+
$driverOptions[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
85+
}
86+
87+
$params = array(
88+
'dbname' => $configDatabase->database->params->dbname,
89+
'username' => $configDatabase->database->params->username,
90+
'password' => $configDatabase->database->params->password,
91+
'driver_options' => $driverOptions,
92+
);
93+
94+
if (empty($configDatabase->database->params->unix_socket)) {
95+
$params['host'] = $configDatabase->database->params->host;
96+
$params['port'] = $configDatabase->database->params->port;
97+
} else {
98+
$params['unix_socket'] = $configDatabase->database->params->unix_socket;
99+
}
88100
}
101+
89102
if ($configGlobal->environment == 'production') {
90103
Zend_Loader::loadClass('ProductionDbProfiler', BASE_PATH.'/core/models/profiler');
91104
$params['profiler'] = new ProductionDbProfiler();
92105
}
106+
93107
$db = Zend_Db::factory($configDatabase->database->adapter, $params);
94108
$db->getProfiler()->setEnabled(true);
95109
Zend_Db_Table::setDefaultAdapter($db);

core/configs/database.ini

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[production]
2-
database.profiler = 0
3-
database.adapter = PDO_MYSQL
4-
database.params.host = localhost
5-
database.params.port = 3306
6-
database.params.unix_socket =
7-
database.params.dbname = midas
8-
database.params.username = root
9-
database.params.password =
4+
database.adapter = "PDO_MYSQL"
5+
database.params.host = "localhost"
6+
database.params.port = "3306"
7+
database.params.unix_socket = ""
8+
database.params.dbname = "midas"
9+
database.params.username = "root"
10+
database.params.password = ""
11+
database.profiler = "0"
12+
version = ""
1013

1114
[development]
12-
database.profiler = 1
13-
database.adapter = PDO_MYSQL
14-
database.params.host = localhost
15-
database.params.port = 3306
16-
database.params.unix_socket =
17-
database.params.dbname = midas
18-
database.params.username = root
19-
database.params.password =
15+
database.adapter = "PDO_MYSQL"
16+
database.params.host = "localhost"
17+
database.params.port = "3306"
18+
database.params.unix_socket = ""
19+
database.params.dbname = "midas"
20+
database.params.username = "root"
21+
database.params.password = ""
22+
database.profiler = "1"
23+
version = ""
2024

2125
[testing]
22-
database.profiler = 1
23-
database.adapter = PDO_MYSQL
24-
database.params.host = localhost
25-
database.params.port = 3306
26-
database.params.unix_socket =
27-
database.params.dbname = midas_test
28-
database.params.username = root
29-
database.params.password =
26+
database.adapter = "PDO_MYSQL"
27+
database.params.host = "localhost"
28+
database.params.port = "3306"
29+
database.params.unix_socket = ""
30+
database.params.dbname = "midas_test"
31+
database.params.username = "root"
32+
database.params.password = ""
33+
database.profiler = "1"
34+
version = ""

core/controllers/AdminController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@ public function showlogAction()
301301
$limit = $this->getParam('limit');
302302
$offset = $this->getParam('offset');
303303
if (!isset($start) || empty($start)) {
304-
$start = date("Y-m-d H:i:s", strtotime('-24 hour'));
304+
$start = date('Y-m-d H:i:s', strtotime('-24 hour'));
305305
} else {
306-
$start = date("Y-m-d H:i:s", strtotime($start));
306+
$start = date('Y-m-d H:i:s', strtotime($start));
307307
}
308308
if (!isset($end) || empty($end)) {
309-
$end = date("Y-m-d H:i:s");
309+
$end = date('Y-m-d H:i:s');
310310
} else {
311-
$end = date("Y-m-d H:i:s", strtotime($end));
311+
$end = date('Y-m-d H:i:s', strtotime($end));
312312
}
313313
if (!isset($module) || empty($module)) {
314314
$module = 'all';

core/controllers/ImportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function _recursiveParseDirectory($path, $currentdir)
167167
$child = new FolderDao();
168168
$child->setName($fileInfo->getFilename());
169169
$child->setParentId($currentdir->getFolderId());
170-
$child->setDateCreation(date("Y-m-d H:i:s"));
170+
$child->setDateCreation(date('Y-m-d H:i:s'));
171171
$child->setDescription('');
172172
$this->Folder->save($child);
173173
$this->Folderpolicyuser->createPolicy($this->userSession->Dao, $child, MIDAS_POLICY_ADMIN);

core/controllers/InstallController.php

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ public function step2Action()
6767
}
6868
$this->view->header = 'Step 2: Database Configuration';
6969

70-
$databases = array('mysql', 'pgsql');
70+
$databases = array('mysql', 'pgsql', 'sqlite');
7171
$this->view->databaseType = array();
7272
foreach ($databases as $database) {
7373
if (!extension_loaded('pdo_'.$database) || !file_exists(BASE_PATH.'/core/database/'.$database)
7474
) {
7575
unset($database);
7676
} else {
7777
$form = $this->Form->Install->createDBForm();
78+
$host = $form->getElement('host');
7879
$port = $form->getElement('port');
7980
$username = $form->getElement('username');
8081
switch ($database) {
@@ -86,6 +87,11 @@ public function step2Action()
8687
$port->setValue('5432');
8788
$username->setValue('postgres');
8889
break;
90+
case 'sqlite':
91+
$host->setValue('');
92+
$port->setValue('');
93+
$username->setValue('');
94+
break;
8995
default:
9096
break;
9197
}
@@ -144,16 +150,18 @@ public function step2Action()
144150
$driverOptions = array();
145151
$params = array(
146152
'dbname' => $form->getValue('dbname'),
147-
'username' => $form->getValue('username'),
148-
'password' => $form->getValue('password'),
149153
'driver_options' => $driverOptions,
150154
);
151-
$unixsocket = $form->getValue('unix_socket');
152-
if ($unixsocket) {
153-
$params['unix_socket'] = $unixsocket;
154-
} else {
155-
$params['host'] = $form->getValue('host');
156-
$params['port'] = $form->getValue('port');
155+
if ($dbtype != 'PDO_SQLITE') {
156+
$params['username'] = $form->getValue('username');
157+
$params['password'] = $form->getValue('password');
158+
$unixsocket = $form->getValue('unix_socket');
159+
if ($unixsocket) {
160+
$params['unix_socket'] = $unixsocket;
161+
} else {
162+
$params['host'] = $form->getValue('host');
163+
$params['port'] = $form->getValue('port');
164+
}
157165
}
158166

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

187+
$configDatabase = new Zend_Config_Ini(LOCAL_CONFIGS_PATH.'/database.local.ini', $configGlobal->environment);
188+
Zend_Registry::set('configDatabase', $configDatabase);
189+
179190
require_once BASE_PATH.'/core/controllers/components/UpgradeComponent.php';
180191
$upgradeComponent = new UpgradeComponent();
181-
$db = Zend_Registry::get('dbAdapter');
182192

183193
$upgradeComponent->initUpgrade('core', $db, $dbtype);
184194
$upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile)));
@@ -268,31 +278,36 @@ public function testconnectionAction()
268278
$this->requireAjaxRequest();
269279
$this->_helper->layout->disableLayout();
270280
$this->_helper->viewRenderer->setNoRender();
271-
try {
272-
$driverOptions = array();
273-
$params = array(
274-
'dbname' => $this->getParam('dbname'),
275-
'username' => $this->getParam('username'),
276-
'password' => $this->getParam('password'),
277-
'driver_options' => $driverOptions,
278-
);
279-
$unixsocket = $this->getParam('unix_socket');
280-
if ($unixsocket) {
281-
$params['unix_socket'] = $this->getParam('unix_socket');
282-
} else {
283-
$params['host'] = $this->getParam('host');
284-
$params['port'] = $this->getParam('port');
285-
}
286-
$db = Zend_Db::factory('PDO_'.strtoupper($this->getParam('type')), $params);
287-
$tables = $db->listTables();
288-
if (count($tables) > 0) {
289-
$return = array(false, 'The database is not empty');
290-
} else {
291-
$return = array(true, 'The database is reachable');
281+
$dbtype = 'PDO_'.strtoupper($this->getParam('type'));
282+
if ($dbtype === 'PDO_SQLITE') {
283+
$return = array(true, 'The database is reachable');
284+
} else {
285+
try {
286+
$driverOptions = array();
287+
$params = array(
288+
'dbname' => $this->getParam('dbname'),
289+
'username' => $this->getParam('username'),
290+
'password' => $this->getParam('password'),
291+
'driver_options' => $driverOptions,
292+
);
293+
$unixsocket = $this->getParam('unix_socket');
294+
if ($unixsocket) {
295+
$params['unix_socket'] = $this->getParam('unix_socket');
296+
} else {
297+
$params['host'] = $this->getParam('host');
298+
$params['port'] = $this->getParam('port');
299+
}
300+
$db = Zend_Db::factory('PDO_'.strtoupper($this->getParam('type')), $params);
301+
$tables = $db->listTables();
302+
if (count($tables) > 0) {
303+
$return = array(false, 'The database is not empty');
304+
} else {
305+
$return = array(true, 'The database is reachable');
306+
}
307+
$db->closeConnection();
308+
} catch (Zend_Exception $exception) {
309+
$return = array(false, 'Could not connect to the database');
292310
}
293-
$db->closeConnection();
294-
} catch (Zend_Exception $exception) {
295-
$return = array(false, 'Could not connect to the database');
296311
}
297312
echo JsonComponent::encode($return);
298313
}

core/controllers/components/ApisystemComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function uploadGeneratetoken($args)
361361
$revision = new ItemRevisionDao();
362362
$revision->setChanges('Initial revision');
363363
$revision->setUser_id($userDao->getKey());
364-
$revision->setDate(date("Y-m-d H:i:s"));
364+
$revision->setDate(date('Y-m-d H:i:s'));
365365
$revision->setLicenseId(null);
366366
$itemModel->addRevision($item, $revision);
367367
}

0 commit comments

Comments
 (0)