/** 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;
 }
Пример #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());
     }
 }
Пример #3
0
 /**
  * Count the total number of bitstreams in the system. Provide an asset store
  * dao if you wish to count the number in a single asset store.
  *
  * @param null|AssetstoreDao $assetstoreDao
  * @return int
  */
 public function countAll($assetstoreDao = null)
 {
     $sql = $this->database->select()->setIntegrityCheck(false)->from('bitstream', array('count' => 'count(*)'));
     if ($assetstoreDao) {
         $sql->where('assetstore_id = ?', $assetstoreDao->getKey());
     }
     $row = $this->database->fetchRow($sql);
     return $row['count'];
 }
Пример #4
0
 /**
  * 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);
     }
 }
Пример #5
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());
     }
 }
Пример #6
0
 /**
  * Move all bitstreams from one asset store to another.
  *
  * @param AssetstoreDao $srcAssetstore The source asset store
  * @param AssetstoreDao $dstAssetstore The destination asset store
  * @param null|ProgressDao $progressDao Progress dao for asynchronous updating
  * @throws Zend_Exception
  */
 public function moveBitstreams($srcAssetstore, $dstAssetstore, $progressDao = null)
 {
     $current = 0;
     /** @var ProgressModel $progressModel */
     $progressModel = MidasLoader::loadModel('Progress');
     /** @var BitstreamModel $bitstreamModel */
     $bitstreamModel = MidasLoader::loadModel('Bitstream');
     $sql = $this->database->select()->setIntegrityCheck(false)->from('bitstream')->where('assetstore_id = ?', $srcAssetstore->getKey());
     $rows = $this->database->fetchAll($sql);
     $srcPath = $srcAssetstore->getPath();
     $dstPath = $dstAssetstore->getPath();
     foreach ($rows as $row) {
         $bitstream = $this->initDao('Bitstream', $row);
         if ($progressDao) {
             ++$current;
             $message = $current . ' / ' . $progressDao->getMaximum() . ': Moving ' . $bitstream->getName() . ' (' . UtilityComponent::formatSize($bitstream->getSizebytes()) . ')';
             $progressModel->updateProgress($progressDao, $current, $message);
         }
         // Move the file on disk to its new location
         $dir1 = substr($bitstream->getChecksum(), 0, 2);
         $dir2 = substr($bitstream->getChecksum(), 2, 2);
         if (!is_dir($dstPath . '/' . $dir1)) {
             if (!mkdir($dstPath . '/' . $dir1)) {
                 throw new Zend_Exception('Failed to mkdir ' . $dstPath . '/' . $dir1);
             }
         }
         if (!is_dir($dstPath . '/' . $dir1 . '/' . $dir2)) {
             if (!mkdir($dstPath . '/' . $dir1 . '/' . $dir2)) {
                 throw new Zend_Exception('Failed to mkdir ' . $dstPath . '/' . $dir1 . '/' . $dir2);
             }
         }
         if (is_file($dstPath . '/' . $bitstream->getPath())) {
             if (is_file($srcPath . '/' . $bitstream->getPath())) {
                 unlink($srcPath . '/' . $bitstream->getPath());
             }
         } else {
             if (!rename($srcPath . '/' . $bitstream->getPath(), $dstPath . '/' . $bitstream->getPath())) {
                 throw new Zend_Exception('Error moving ' . $bitstream->getPath());
             }
         }
         // Update the asset store id on the bitstream record once it has been moved
         $bitstream->setAssetstoreId($dstAssetstore->getKey());
         $bitstreamModel->save($bitstream);
     }
 }
Пример #7
0
 /**
  * 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;
 }
Пример #8
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');
         }
     }
 }
Пример #9
0
 /**
  * Upload a bitstream.
  *
  * @param BitstreamDao $bitstreamdao
  * @param AssetstoreDao $assetstoredao
  * @param bool $copy
  * @return bool
  * @throws Zend_Exception
  */
 public function uploadBitstream($bitstreamdao, $assetstoredao, $copy = false)
 {
     $assetstoretype = $assetstoredao->getType();
     switch ($assetstoretype) {
         case MIDAS_ASSETSTORE_LOCAL:
             $this->_uploadLocalBitstream($bitstreamdao, $assetstoredao, $copy);
             break;
         case MIDAS_ASSETSTORE_REMOTE:
             // Nothing to upload in that case, we return silently
             return true;
         default:
             break;
     }
     return true;
 }
Пример #10
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);
}
Пример #11
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);
 }