/** init tests */
 public function setUp()
 {
     $this->setupDatabase(array('default'));
     $this->_models = array('Assetstore', 'Bitstream', 'User');
     $this->_daos = array('Assetstore', 'User');
     parent::setUp();
     $this->loadUsers();
     // create another assetstore
     $testAssetstoreBase = $this->getTempDirectory() . '/test/';
     $testAssetstoreBase = str_replace('tests/../', '', $testAssetstoreBase);
     $testAssetstoreBase = str_replace('//', '/', $testAssetstoreBase);
     $testAssetstore2 = $testAssetstoreBase . '/assetstore2';
     if (!is_dir($testAssetstore2)) {
         mkdir($testAssetstore2);
     }
     $testAssetstoreAdditionalPath = $testAssetstoreBase . '/additionalpathassetstore2';
     if (!is_dir($testAssetstoreAdditionalPath)) {
         mkdir($testAssetstoreAdditionalPath);
     }
     $this->testAssetstoreAdditionalPath = $testAssetstoreAdditionalPath;
     $testAssetstoreDao = new AssetstoreDao();
     $testAssetstoreDao->setName('testassetstore2');
     $testAssetstoreDao->setPath($testAssetstore2);
     $testAssetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
     $this->Assetstore->save($testAssetstoreDao);
     $this->testAssetstoreDao = $testAssetstoreDao;
 }
Example #2
0
 /** Init controller */
 public function init()
 {
     $maxFile = str_replace('M', '', ini_get('upload_max_filesize'));
     $maxPost = str_replace('M', '', ini_get('post_max_size'));
     if ($maxFile < $maxPost) {
         $this->view->maxSizeFile = $maxFile * 1024 * 1024;
     } else {
         $this->view->maxSizeFile = $maxPost * 1024 * 1024;
     }
     if ($this->isTestingEnv()) {
         $assetstores = $this->Assetstore->getAll();
         if (empty($assetstores)) {
             $assetstoreDao = new AssetstoreDao();
             $assetstoreDao->setName('Default');
             $assetstoreDao->setPath($this->getDataDirectory('assetstore'));
             $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
             $this->Assetstore = new AssetstoreModel();
             // reset Database adapter
             $this->Assetstore->save($assetstoreDao);
         } else {
             $assetstoreDao = $assetstores[0];
         }
         $this->Setting->setConfig('default_assetstore', $assetstoreDao->getKey());
     }
 }
 /**
  * helper function, attempts to save an Assetstore, using either the passed in
  * assetstoreDao or creating a new one, will set the three parameter
  * values before saving, expects that the save will fail, and asserts
  * that an exception has been thrown by the Assetstore Model.
  *
  * @param type $name
  * @param type $path
  * @param type $type
  * @param AssetstoreDao $assetstoreDao
  */
 protected function invalidSaveTestcase($name, $path, $type, $assetstoreDao = null)
 {
     if (empty($assetstoreDao)) {
         $assetstoreDao = new AssetstoreDao();
     }
     $assetstoreDao->setName($name);
     $assetstoreDao->setPath($path);
     $assetstoreDao->setType($type);
     try {
         $this->Assetstore->save($assetstoreDao);
         $this->fail('Expected an exception saving assetstoreDao, but did not get one.');
     } catch (Zend_Exception $ze) {
         // if we got here, this is the correct behavior
         $this->assertTrue(true);
     }
 }
Example #4
0
 /** Init controller */
 public function init()
 {
     if ($this->isTestingEnv()) {
         $assetstores = $this->Assetstore->getAll();
         if (empty($assetstores)) {
             $assetstoreDao = new AssetstoreDao();
             $assetstoreDao->setName('Default');
             $assetstoreDao->setPath($this->getDataDirectory('assetstore'));
             $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
             $this->Assetstore = new AssetstoreModel();
             $this->Assetstore->save($assetstoreDao);
         } else {
             $assetstoreDao = $assetstores[0];
         }
         $this->Setting->setConfig('default_assetstore', $assetstoreDao->getKey());
     }
 }
 /**
  * called from ajax.
  */
 public function addAction()
 {
     $this->requireAdminPrivileges();
     $this->disableLayout();
     $this->disableView();
     $form = $this->Form->Assetstore->createAssetstoreForm();
     if ($this->getRequest()->isPost() && !$form->isValid($_POST)) {
         echo json_encode(array('error' => 'Missing or invalid form values.'));
         return false;
     }
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         // Save the assetstore in the database
         $assetstoreDao = new AssetstoreDao();
         $assetstoreDao->setName($form->name->getValue());
         $assetstoreDao->setPath($form->basedirectory->getValue());
         $assetstoreDao->setType($form->assetstoretype->getValue());
         if (!is_dir($assetstoreDao->getPath())) {
             echo JsonComponent::encode(array('error' => 'The path provided is not a valid directory'));
             return false;
         }
         if (!is_writable($assetstoreDao->getPath())) {
             echo JsonComponent::encode(array('error' => 'The specified directory is not writable'));
             return false;
         }
         try {
             $this->Assetstore->save($assetstoreDao);
         } catch (Zend_Exception $ze) {
             echo JsonComponent::encode(array('error' => $ze->getMessage()));
             return false;
         }
         $totalSpace = UtilityComponent::diskTotalSpace($assetstoreDao->getPath());
         $freeSpace = UtilityComponent::diskFreeSpace($assetstoreDao->getPath());
         echo JsonComponent::encode(array('msg' => 'The assetstore has been added.', 'assetstore_id' => $assetstoreDao->getAssetstoreId(), 'assetstore_name' => $assetstoreDao->getName(), 'assetstore_type' => $assetstoreDao->getType(), 'totalSpace' => $totalSpace, 'totalSpaceText' => $this->Component->Utility->formatSize($totalSpace), 'freeSpace' => $freeSpace, 'freeSpaceText' => $this->Component->Utility->formatSize($freeSpace)));
         return true;
     }
     echo json_encode(array('error' => 'Bad request.'));
     return false;
 }
Example #6
0
 /**
  */
 public function step2Action()
 {
     if (file_exists(LOCAL_CONFIGS_PATH . '/database.local.ini')) {
         $this->redirect('/install/step3');
     }
     $this->view->header = 'Step 2: Database Configuration';
     $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) {
                 case 'mysql':
                     $port->setValue('3306');
                     $username->setValue('root');
                     break;
                 case 'pgsql':
                     $port->setValue('5432');
                     $username->setValue('postgres');
                     break;
                 case 'sqlite':
                     $host->setValue('');
                     $port->setValue('');
                     $username->setValue('');
                     break;
                 default:
                     break;
             }
             $this->view->databaseType[$database] = $this->getFormAsArray($form);
         }
     }
     $this->view->basePath = BASE_PATH;
     if ($this->_request->isPost()) {
         $type = $this->getParam('type');
         $form = $this->Form->Install->createDBForm();
         if ($form->isValid($this->getRequest()->getPost())) {
             require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php';
             $upgradeComponent = new UpgradeComponent();
             $upgradeComponent->dir = BASE_PATH . '/core/database/' . $type;
             $upgradeComponent->init = true;
             $sqlFile = $upgradeComponent->getNewestVersion(true);
             $sqlFile = BASE_PATH . '/core/database/' . $type . '/' . $sqlFile . '.sql';
             if (!isset($sqlFile) || !file_exists($sqlFile)) {
                 throw new Zend_Exception('Unable to find sql file');
             }
             $dbtype = 'PDO_' . strtoupper($type);
             $version = str_replace('.sql', '', basename($sqlFile));
             $options = array('allowModifications' => true);
             $databaseConfig = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/database.ini', null, $options);
             $databaseConfig->production->database->adapter = $dbtype;
             $databaseConfig->production->database->params->host = $form->getValue('host');
             $databaseConfig->production->database->params->port = $form->getValue('port');
             $databaseConfig->production->database->params->unix_socket = $form->getValue('unix_socket');
             $databaseConfig->production->database->params->dbname = $form->getValue('dbname');
             $databaseConfig->production->database->params->username = $form->getValue('username');
             $databaseConfig->production->database->params->password = $form->getValue('password');
             $databaseConfig->production->version = $version;
             $databaseConfig->development->database->adapter = $dbtype;
             $databaseConfig->development->database->params->host = $form->getValue('host');
             $databaseConfig->development->database->params->port = $form->getValue('port');
             $databaseConfig->development->database->params->unix_socket = $form->getValue('unix_socket');
             $databaseConfig->development->database->params->dbname = $form->getValue('dbname');
             $databaseConfig->development->database->params->username = $form->getValue('username');
             $databaseConfig->development->database->params->password = $form->getValue('password');
             $databaseConfig->development->version = $version;
             $writer = new Zend_Config_Writer_Ini();
             $writer->setConfig($databaseConfig);
             $writer->setFilename(LOCAL_CONFIGS_PATH . '/database.local.ini');
             $writer->write();
             $driverOptions = array();
             $params = array('dbname' => $form->getValue('dbname'), 'driver_options' => $driverOptions);
             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);
             Zend_Db_Table::setDefaultAdapter($db);
             Zend_Registry::set('dbAdapter', $db);
             $this->Component->Utility->run_sql_from_file($db, $sqlFile);
             // Must generate and store our password salt before we create our first user
             $options = array('allowModifications' => true);
             $applicationConfig = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/application.ini', null, $options);
             $prefix = $this->Component->Random->generateString(32);
             $applicationConfig->global->password->prefix = $prefix;
             $applicationConfig->global->gravatar = $form->getValue('gravatar');
             $writer = new Zend_Config_Writer_Ini();
             $writer->setConfig($applicationConfig);
             $writer->setFilename(LOCAL_CONFIGS_PATH . '/application.local.ini');
             $writer->write();
             $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', 'production');
             Zend_Registry::set('configDatabase', $configDatabase);
             require_once BASE_PATH . '/core/controllers/components/UpgradeComponent.php';
             $upgradeComponent = new UpgradeComponent();
             $upgradeComponent->initUpgrade('core', $db, $dbtype);
             $upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile)));
             session_start();
             require_once BASE_PATH . '/core/models/pdo/UserModel.php';
             $userModel = new UserModel();
             $this->userSession->Dao = $userModel->createUser($form->getValue('email'), $form->getValue('userpassword1'), $form->getValue('firstname'), $form->getValue('lastname'), 1);
             // create default assetstore
             $assetstoreDao = new AssetstoreDao();
             $assetstoreDao->setName('Local');
             $assetstoreDao->setPath($this->getDataDirectory('assetstore'));
             $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
             $this->Assetstore = new AssetstoreModel();
             // reset Database adapter
             $this->Assetstore->save($assetstoreDao);
             $this->redirect('/install/step3');
         }
     }
 }
Example #7
0
/** Create default asset store. */
function createDefaultAssetstore()
{
    Zend_Registry::set('models', array());
    /** @var AssetstoreModel $assetStoreModel */
    $assetStoreModel = MidasLoader::loadModel('Assetstore');
    // path munging
    require_once BASE_PATH . '/core/controllers/components/UtilityComponent.php';
    $testAssetstoreBase = UtilityComponent::getTempDirectory() . '/test/';
    $testAssetstoreBase = str_replace('tests/../', '', $testAssetstoreBase);
    $testAssetstoreBase = str_replace('//', '/', $testAssetstoreBase);
    // create assetstore directory
    if (!is_dir($testAssetstoreBase)) {
        mkdir($testAssetstoreBase);
    }
    $testAssetstore = $testAssetstoreBase . '/assetstore';
    if (!is_dir($testAssetstore)) {
        mkdir($testAssetstore);
    }
    // create default assetstore in db
    require_once BASE_PATH . '/core/models/dao/AssetstoreDao.php';
    $assetstoreDao = new AssetstoreDao();
    $assetstoreDao->setName('Default');
    $assetstoreDao->setPath($testAssetstore);
    $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
    $assetStoreModel->save($assetstoreDao);
}
Example #8
0
 /** Reset database (only works with MySQL) */
 public function reset()
 {
     $db = Zend_Registry::get('dbAdapter');
     $dbname = Zend_Registry::get('configDatabase')->database->params->dbname;
     $stmt = $db->query("SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = '" . $dbname . "'");
     while ($row = $stmt->fetch()) {
         $db->query('DELETE FROM `' . $row['TABLE_NAME'] . '`');
     }
     $path = UtilityComponent::getDataDirectory('assetstore');
     $dir = opendir($path);
     while ($entry = readdir($dir)) {
         if (is_dir($path . '/' . $entry) && !in_array($entry, array('.', '..'))) {
             $this->_rrmdir($path . '/' . $entry);
         }
     }
     $path = UtilityComponent::getDataDirectory('thumbnail');
     $dir = opendir($path);
     while ($entry = readdir($dir)) {
         if (is_dir($path . '/' . $entry) && !in_array($entry, array('.', '..'))) {
             $this->_rrmdir($path . '/' . $entry);
         }
     }
     if (file_exists(LOCAL_CONFIGS_PATH . '/ldap.local.ini')) {
         unlink(LOCAL_CONFIGS_PATH . '/ldap.local.ini');
     }
     /** @var UserModel $userModel */
     $userModel = MidasLoader::loadModel('User');
     $admin = $userModel->createUser(MIDAS_DEMO_ADMIN_EMAIL, MIDAS_DEMO_ADMIN_PASSWORD, 'Demo', 'Administrator', 1);
     $userModel->createUser(MIDAS_DEMO_USER_EMAIL, MIDAS_DEMO_USER_PASSWORD, 'Demo', 'User', 0);
     /** @var CommunityModel $communityModel */
     $communityModel = MidasLoader::loadModel('Community');
     $communityDao = $communityModel->createCommunity('Demo', 'This is a demo community', MIDAS_COMMUNITY_PUBLIC, $admin, MIDAS_COMMUNITY_CAN_JOIN);
     /** @var AssetstoreModel $assetstoreModel */
     $assetstoreModel = MidasLoader::loadModel('Assetstore');
     $assetstoreDao = new AssetstoreDao();
     $assetstoreDao->setName('Default');
     $assetstoreDao->setPath(UtilityComponent::getDataDirectory('assetstore'));
     $assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
     $assetstoreModel->save($assetstoreDao);
     /** @var SettingModel $settingModel */
     $settingModel = MidasLoader::loadModel('Setting');
     $settingModel->setConfig('default_assetstore', $assetstoreDao->getKey());
     $options = array('allowModifications' => true);
     $config = new Zend_Config_Ini(CORE_CONFIGS_PATH . '/application.ini', null, $options);
     $config->global->dynamichelp = 1;
     $config->global->environment = 'production';
     $config->global->application->name = 'Midas Platform - Demo';
     $description = 'Midas Platform is an open-source toolkit that enables the
   rapid creation of tailored, web-enabled data storage. Designed to meet
   the needs of advanced data-centric computing, Midas Platform addresses
   the growing challenge of large data by providing a flexible, intelligent
   data storage system. The system integrates multimedia server technology
   with other open-source data analysis and visualization tools to enable
   data-intensive applications that easily interface with existing
   workflows.';
     $config->global->application->description = $description;
     $enabledModules = array('api', 'metadataextractor', 'oai', 'statistics', 'scheduler', 'thumbnailcreator', 'visualize');
     foreach ($enabledModules as $module) {
         if (file_exists(LOCAL_CONFIGS_PATH . '/' . $module . '.demo.local.ini')) {
             copy(LOCAL_CONFIGS_PATH . '/' . $module . '.demo.local.ini', LOCAL_CONFIGS_PATH . '/' . $module . '.local.ini');
             $config->module->{$module} = 1;
         } else {
             unlink(LOCAL_CONFIGS_PATH . '/' . $module . '.local.ini');
         }
     }
     $writer = new Zend_Config_Writer_Ini();
     $writer->setConfig($config);
     $writer->setFilename(LOCAL_CONFIGS_PATH . '/application.local.ini');
     $writer->write();
     $configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true);
     Zend_Registry::set('configGlobal', $configGlobal);
     /** @var UploadComponent $uploadComponent */
     $uploadComponent = MidasLoader::loadComponent('Upload');
     $uploadComponent->createUploadedItem($admin, 'midasLogo.gif', BASE_PATH . '/core/public/images/midasLogo.gif', $communityDao->getPublicFolder(), null, '', true);
     $uploadComponent->createUploadedItem($admin, 'cow.vtp', BASE_PATH . '/modules/demo/public/' . $this->moduleName . '/cow.vtp', $communityDao->getPublicFolder(), null, '', true);
 }