/** * Create a thumbnail bitstream in the provided assetstore using the * passed tempThumbnailFile, which will be moved to the assetstore. * * @return The bitstream dao that was created for the thumbnail */ public function createThumbnail($assetstore, $tempThumbnailFile) { /** @var BitstreamDao $bitstreamDao */ $bitstreamDao = MidasLoader::newDao('BitstreamDao'); $md5 = md5_file($tempThumbnailFile); $bitstreamDao->setName('thumbnail.jpeg'); $bitstreamDao->setItemrevisionId(-1); //-1 indicates this does not belong to any revision $bitstreamDao->setMimetype('image/jpeg'); $bitstreamDao->setSizebytes(filesize($tempThumbnailFile)); $bitstreamDao->setDate(date('Y-m-d H:i:s')); $bitstreamDao->setChecksum($md5); $existing = $this->getByChecksum($md5); if ($existing) { unlink($tempThumbnailFile); $bitstreamDao->setPath($existing->getPath()); $bitstreamDao->setAssetstoreId($existing->getAssetstoreId()); } else { $path = substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . $md5; $fullpath = $assetstore->getPath() . '/' . $path; $currentdir = $assetstore->getPath() . '/' . substr($md5, 0, 2); $this->_createAssetstoreDirectory($currentdir); $currentdir .= '/' . substr($md5, 2, 2); $this->_createAssetstoreDirectory($currentdir); rename($tempThumbnailFile, $fullpath); $bitstreamDao->setAssetstoreId($assetstore->getKey()); $bitstreamDao->setPath($path); } $this->save($bitstreamDao); return $bitstreamDao; }
/** Post database upgrade. */ public function postUpgrade() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $configPath = LOCAL_CONFIGS_PATH . DIRECTORY_SEPARATOR . $this->moduleName . '.local.ini'; if (file_exists($configPath)) { $config = new Zend_Config_Ini($configPath, 'global'); $settingModel->setConfig(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, $config->get('dcm2xml', DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE), $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, $config->get('dcmj2pnm', DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE), $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, $config->get('dcmftest', DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE), $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMDICTPATH_KEY, $config->get('dcmdictpath', DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE), $this->moduleName); $config = new Zend_Config_Ini($configPath, null, true); unset($config->global->dcm2xml); unset($config->global->dcmj2pnm); unset($config->global->dcmftest); unset($config->global->dcmdictpath); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename($configPath); $writer->write(); } else { $settingModel->setConfig(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(DICOMEXTRACTOR_DCMDICTPATH_KEY, DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE, $this->moduleName); } }
/** Post database install. */ public function postInstall() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $settingModel->setConfig(MIDAS_SIZEQUOTA_DEFAULT_USER_QUOTA_KEY, MIDAS_SIZEQUOTA_DEFAULT_USER_QUOTA_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(MIDAS_SIZEQUOTA_DEFAULT_COMMUNITY_QUOTA_KEY, MIDAS_SIZEQUOTA_DEFAULT_COMMUNITY_QUOTA_DEFAULT_VALUE, $this->moduleName); }
/** * Generate an upload token that will act as the authentication token for the upload. * This token is the filename of a unique file which will be placed under the * directory specified by the dirname parameter, which should be used to ensure that * the user can only write into a certain logical space. * * @param array $args * @param string $dirname * @return array * @throws Exception */ public function generateToken($args, $dirname = '') { if (!array_key_exists('filename', $args)) { throw new Exception('Parameter filename is not defined', MIDAS_HTTPUPLOAD_FILENAME_PARAM_UNDEFINED); } $tempDirectory = UtilityComponent::getTempDirectory(); $dir = $dirname === '' ? '' : '/' . $dirname; $dir = $tempDirectory . $dir; if (!file_exists($dir)) { if (!mkdir($dir, 0777, true)) { throw new Exception('Failed to create temporary upload dir', MIDAS_HTTPUPLOAD_TMP_DIR_CREATION_FAILED); } } /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $uniqueIdentifier = $randomComponent->generateString(64); if ($dirname != '') { $uniqueIdentifier = $dirname . '/' . $uniqueIdentifier; } $path = $tempDirectory . '/' . $uniqueIdentifier; if (file_exists($path)) { throw new Exception('Failed to generate upload token', MIDAS_HTTPUPLOAD_UPLOAD_TOKEN_GENERATION_FAILED); } if (touch($path) === false) { mkdir($path, 0777, true); $uniqueIdentifier .= '/'; } return array('token' => $uniqueIdentifier); }
/** create a policy * @return FeedpolicyuserDao */ public function createPolicy($user, $feed, $policy) { if (!$user instanceof UserDao) { throw new Zend_Exception('Should be a user.'); } if (!$feed instanceof FeedDao) { throw new Zend_Exception('Should be a feed.'); } if (!is_numeric($policy)) { throw new Zend_Exception('Should be a number.'); } if (!$user->saved && !$feed->saved) { throw new Zend_Exception('Save the daos first.'); } if ($this->getPolicy($user, $feed) !== false) { $this->delete($this->getPolicy($user, $feed)); } /** @var FeedpolicyuserDao $policyUser */ $policyUser = MidasLoader::newDao('FeedpolicyuserDao'); $policyUser->setUserId($user->getUserId()); $policyUser->setFeedId($feed->getFeedId()); $policyUser->setPolicy($policy); $this->save($policyUser); return $policyUser; }
/** * Schedule or cancel the send report job. * * @param bool $schedule schedule the job if true, cancel the job if false * @param null|UserDao $userDao user scheduling the job * * @throws Zend_Exception */ public function scheduleOrCancelSendReportJob($schedule, $userDao = null) { /** @var Scheduler_JobModel $jobModel */ $jobModel = MidasLoader::loadModel('Job', 'scheduler'); $jobDaos = $jobModel->getJobsByTask('TASK_STATISTICS_SEND_REPORT'); $reportJobDao = false; foreach ($jobDaos as $jobDao) { if ($jobDao->getTask() === 'TASK_STATISTICS_SEND_REPORT') { $reportJobDao = $jobDao; break; } } if ($schedule) { if ($reportJobDao === false) { /** @var Scheduler_JobDao $reportJobDao */ $reportJobDao = MidasLoader::newDao('JobDao', 'scheduler'); $reportJobDao->setTask('TASK_STATISTICS_SEND_REPORT'); $reportJobDao->setPriority(1); $reportJobDao->setRunOnlyOnce(0); $reportJobDao->setFireTime(date('Y-m-d', strtotime('+1 day' . date('Y-m-d H:i:s'))) . ' 01:00:00'); $reportJobDao->setTimeInterval(86400); $reportJobDao->setStatus(SCHEDULER_JOB_STATUS_TORUN); $reportJobDao->setCreatorId($this->userSession->Dao->getKey()); $reportJobDao->setParams(JsonComponent::encode(array())); if (!is_null($userDao)) { $reportJobDao->setCreatorId($userDao->getKey()); } $jobModel->save($reportJobDao); } } else { if ($reportJobDao !== false) { $jobModel->delete($reportJobDao); } } }
/** Post database upgrade. */ public function postUpgrade() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $configPath = LOCAL_CONFIGS_PATH . DIRECTORY_SEPARATOR . $this->moduleName . '.local.ini'; if (file_exists($configPath)) { $config = new Zend_Config_Ini($configPath, 'global'); $piwikUrl = isset($config->piwik->url) ? $config->piwik->url : STATISTICS_PIWIK_URL_DEFAULT_VALUE; $settingModel->setConfig(STATISTICS_PIWIK_URL_KEY, $piwikUrl, $this->moduleName); $piwikId = isset($config->piwik->id) ? $config->piwik->id : STATISTICS_PIWIK_SITE_ID_DEFAULT_VALUE; $settingModel->setConfig(STATISTICS_PIWIK_SITE_ID_KEY, $piwikId, $this->moduleName); $piwikApiKey = isset($config->piwik->apikey) ? $config->piwik->apikey : STATISTICS_PIWIK_API_KEY_DEFAULT_VALUE; $settingModel->setConfig(STATISTICS_PIWIK_API_KEY_KEY, $piwikApiKey, $this->moduleName); $ipInfoDbApiKey = isset($config->ipinfodb->apikey) ? $config->ipinfodb->apikey : STATISTICS_IP_INFO_DB_API_KEY_DEFAULT_VALUE; $settingModel->setConfig(STATISTICS_IP_INFO_DB_API_KEY_KEY, $ipInfoDbApiKey, $this->moduleName); $settingModel->setConfig(STATISTICS_SEND_DAILY_REPORTS_KEY, $config->get('report', STATISTICS_SEND_DAILY_REPORTS_DEFAULT_VALUE), $this->moduleName); $config = new Zend_Config_Ini($configPath, null, true); unset($config->global->piwik->url); unset($config->global->piwik->id); unset($config->global->piwik->pikey); unset($config->global->ipinfodb->apikey); unset($config->global->report); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename($configPath); $writer->write(); } else { $settingModel->setConfig(STATISTICS_PIWIK_URL_KEY, STATISTICS_PIWIK_URL_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(STATISTICS_PIWIK_SITE_ID_KEY, STATISTICS_PIWIK_SITE_ID_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(STATISTICS_PIWIK_API_KEY_KEY, STATISTICS_PIWIK_API_KEY_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(STATISTICS_IP_INFO_DB_API_KEY_KEY, STATISTICS_IP_INFO_DB_API_KEY_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(STATISTICS_SEND_DAILY_REPORTS_KEY, STATISTICS_SEND_DAILY_REPORTS_DEFAULT_VALUE, $this->moduleName); } }
/** * Fetch the information about an ItemRevision. * * @path /itemrevision/{id} * @http GET * @param id The id of the ItemRevision * @return ItemRevision object * * @param array $args parameters * @throws Exception */ public function itemrevisionGet($args) { /** @var ApihelperComponent $apihelperComponent */ $apihelperComponent = MidasLoader::loadComponent('Apihelper'); $apihelperComponent->validateParams($args, array('id')); $apihelperComponent->requirePolicyScopes(array(MIDAS_API_PERMISSION_SCOPE_READ_DATA)); $userDao = $apihelperComponent->getUser($args); $itemrevision_id = $args['id']; /** @var ItemRevisionModel $itemRevisionModel */ $itemRevisionModel = MidasLoader::loadModel('ItemRevision'); $itemRevision = $itemRevisionModel->load($itemrevision_id); /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); $item = $itemModel->load($itemRevision->getItemId()); if ($item === false || !$itemModel->policyCheck($item, $userDao, MIDAS_POLICY_READ)) { throw new Exception("This item doesn't exist or you don't have the permissions.", MIDAS_INVALID_POLICY); } $in = $itemRevision->toArray(); $out = array(); $out['id'] = $in['itemrevision_id']; $out['item_id'] = $in['item_id']; $out['date_created'] = $in['date']; $out['date_updated'] = $in['date']; // fix this $out['changes'] = $in['changes']; $out['user_id'] = $in['user_id']; $out['license_id'] = $in['license_id']; $out['uuid'] = $in['uuid']; $out['bitstreams'] = array_map(array($this, 'getBitstreamId'), $itemRevision->getBitstreams()); return $out; }
/** @return ItempolicyuserDao */ public function createPolicy($user, $item, $policy) { if (!$user instanceof UserDao) { throw new Zend_Exception('Should be a user.'); } if (!$item instanceof ItemDao) { throw new Zend_Exception('Should be an item.'); } if (!is_numeric($policy)) { throw new Zend_Exception('Should be a number.'); } if (!$user->saved && !$item->saved) { throw new Zend_Exception('Save the daos first.'); } $policyUser = $this->getPolicy($user, $item); if ($policyUser !== false) { $this->delete($policyUser); } /** @var ItempolicyuserDao $policyUser */ $policyUser = MidasLoader::newDao('ItempolicyuserDao'); $policyUser->setUserId($user->getUserId()); $policyUser->setItemId($item->getItemId()); $policyUser->setPolicy($policy); $this->save($policyUser); return $policyUser; }
/** * Extract the dicom metadata from a revision. * * @param item the id of the item to be extracted * @return the id of the revision */ public function extract($args) { /** @var ApihelperComponent $ApihelperComponent */ $ApihelperComponent = MidasLoader::loadComponent('Apihelper'); $ApihelperComponent->renameParamKey($args, 'item', 'id'); return $this->_callModuleApiMethod($args, 'extract', 'item'); }
/** * Test that we receive the correct daily totals from our model. */ public function testDailyTotals() { /** @var Statistics_DownloadModel $downloadModel */ $downloadModel = MidasLoader::loadModel('Download', 'statistics'); // Add 50 downloads 3 days ago for ($i = 0; $i < 50; ++$i) { /** @var Statistics_DownloadDao $dao */ $dao = MidasLoader::newDao('DownloadDao', 'statistics'); $dao->setItemId(7); $dao->setIpLocationId(1); $dao->setDate(date('Y-m-d 01:' . str_pad($i, 2, '0', STR_PAD_LEFT) . ':00', strtotime('-3 day'))); $downloadModel->save($dao); } // Add 20 downloads 2 days ago for ($i = 0; $i < 20; ++$i) { /** @var Statistics_DownloadDao $dao */ $dao = MidasLoader::newDao('DownloadDao', 'statistics'); $dao->setItemId(7); $dao->setIpLocationId(1); $dao->setDate(date('Y-m-d 01:' . str_pad($i, 2, '0', STR_PAD_LEFT) . ':00', strtotime('-2 day'))); $downloadModel->save($dao); } $arrayDownload = $downloadModel->getDailyCounts(array(7), date('Y-m-d H:i:s', strtotime('-20 day' . date('Y-m-d G:i:s'))), date('Y-m-d H:i:s')); $this->assertEquals(count($arrayDownload), 2); $this->assertEquals($arrayDownload[date('Y-m-d', strtotime('-3 day'))], 50); $this->assertEquals($arrayDownload[date('Y-m-d', strtotime('-2 day'))], 20); }
/** * Call this function to acquire the download lock. * This will return false if an active download already exists for * this ip address, otherwise it will return the active download * lock that was created. */ public function acquireLock() { $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip .= '_' . $_SERVER['HTTP_X_FORWARDED_FOR']; } $oldLock = $this->getByIp($ip); if ($oldLock !== false) { // If an old lock exists but has not been updated in more than 5 minutes, we // should release the old lock and create a new one. $lastUpdate = strtotime($oldLock->getLastUpdate()); if (time() > $lastUpdate + 300) { $this->delete($oldLock); } else { return false; } } /** @var ActivedownloadDao $activeDownload */ $activeDownload = MidasLoader::newDao('ActivedownloadDao'); $activeDownload->setDateCreation(date('Y-m-d H:i:s')); $activeDownload->setLastUpdate(date('Y-m-d H:i:s')); $activeDownload->setIp($ip); $this->save($activeDownload); return $activeDownload; }
/** testGetAll */ public function testGetAll() { /** @var Packages_PackageModel $packageModel */ $packageModel = MidasLoader::loadModel('Package', 'packages'); $daos = $packageModel->getAll(); $this->assertEquals(1, count($daos)); }
/** create a policy * @return FeedpolicygroupDao */ public function createPolicy($group, $feed, $policy) { if (!$group instanceof GroupDao) { throw new Zend_Exception('Should be a group.'); } if (!$feed instanceof FeedDao) { throw new Zend_Exception('Should be a feedDao.'); } if (!is_numeric($policy)) { throw new Zend_Exception('Should be a number.'); } if (!$group->saved && !$feed->saved) { throw new Zend_Exception('Save the daos first.'); } if ($this->getPolicy($group, $feed) !== false) { $this->delete($this->getPolicy($group, $feed)); } /** @var FeedpolicygroupDao $policyGroupDao */ $policyGroupDao = MidasLoader::newDao('FeedpolicygroupDao'); $policyGroupDao->setGroupId($group->getGroupId()); $policyGroupDao->setFeedId($feed->getFeedId()); $policyGroupDao->setPolicy($policy); $this->save($policyGroupDao); return $policyGroupDao; }
/** * Submit your OTP after calling core login, and you will receive your api token. * * @param otp The one-time password * @param mfaTokenId The id of the temporary MFA token * @return The api token * @throws Exception */ public function otpLogin($params) { $this->_checkKeys(array('otp', 'mfaTokenId'), $params); /** @var Mfa_ApitokenModel $tempTokenModel */ $tempTokenModel = MidasLoader::loadModel('Apitoken', 'mfa'); /** @var Mfa_OtpdeviceModel $otpDeviceModel */ $otpDeviceModel = MidasLoader::loadModel('Otpdevice', 'mfa'); /** @var TokenModel $apiTokenModel */ $apiTokenModel = MidasLoader::loadModel('Token'); $tempToken = $tempTokenModel->load($params['mfaTokenId']); if (!$tempToken) { throw new Exception('Invalid MFA token id', -1); } $apiToken = $apiTokenModel->load($tempToken->getTokenId()); if (!$apiToken) { $tempTokenModel->delete($tempToken); throw new Exception('Corresponding api token no longer exists', -1); } $user = $tempToken->getUser(); $otpDevice = $otpDeviceModel->getByUser($user); if (!$otpDevice) { $tempTokenModel->delete($tempToken); throw new Exception('User does not have an OTP device', -1); } $tempTokenModel->delete($tempToken); /** @var Mfa_OtpComponent $otpComponent */ $otpComponent = MidasLoader::loadComponent('Otp', 'mfa'); if (!$otpComponent->authenticate($otpDevice, $params['otp'])) { throw new Exception('Incorrect OTP', -1); } $token = $apiToken->getToken(); return array('token' => $token); }
/** * Set a rating on an item. * * @param itemId The item id to set the rating on * @param rating The rating (0-5) to set for the currently logged user. 0 means remove user's rating. * @throws Zend_Exception */ public function rateitemAction() { if (!$this->logged) { throw new Zend_Exception('Must be logged in to rate an item'); } $itemId = $this->getParam('itemId'); if (!isset($itemId) || !$itemId) { throw new Zend_Exception('Must set itemId parameter'); } $item = $this->Item->load($itemId); if (!$item) { throw new Zend_Exception('Not a valid itemId'); } $rating = (int) $this->getParam('rating'); if ($rating < 0 || $rating > 5) { throw new Zend_Exception('Rating must be 0-5'); } $this->disableView(); $this->disableLayout(); /** @var Ratings_ItemratingModel $itemRatingModel */ $itemRatingModel = MidasLoader::loadModel('Itemrating', $this->moduleName); $itemRatingModel->setRating($this->userSession->Dao, $item, $rating); $info = $itemRatingModel->getAggregateInfo($item); $message = $rating == 0 ? 'Rating removed' : 'Rating saved'; echo JsonComponent::encode(array_merge(array('status' => 'ok', 'message' => $message), $info)); }
/** create a policy * @return FolderpolicygroupDao */ public function createPolicy($group, $folder, $policy) { if (!$group instanceof GroupDao) { throw new Zend_Exception('Should be a group.'); } if (!$folder instanceof FolderDao) { throw new Zend_Exception('Should be a folder.'); } if (!is_numeric($policy)) { throw new Zend_Exception('Should be a number.'); } if (!$group->saved && !$folder->saved) { throw new Zend_Exception('Save the daos first.'); } $policyGroupDao = $this->getPolicy($group, $folder); if ($policyGroupDao !== false) { $this->delete($policyGroupDao); } /** @var FolderpolicygroupDao $policyGroupDao */ $policyGroupDao = MidasLoader::newDao('FolderpolicygroupDao'); $policyGroupDao->setGroupId($group->getGroupId()); $policyGroupDao->setFolderId($folder->getFolderId()); $policyGroupDao->setPolicy($policy); $this->save($policyGroupDao); if ($policyGroupDao->getGroupId() == MIDAS_GROUP_ANONYMOUS_KEY) { $this->computePolicyStatus($folder); } return $policyGroupDao; }
/** add a download record for the given item */ public function addDownload($item, $user) { if (!$item instanceof ItemDao) { throw new Zend_Exception('Error: item parameter is not an item dao'); } $userAgent = array_key_exists('HTTP_USER_AGENT', $_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : ''; $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } /** @var Statistics_IpLocationModel $ipLocationModel */ $ipLocationModel = MidasLoader::loadModel('IpLocation', 'statistics'); $ipLocation = $ipLocationModel->getByIp($ip); if ($ipLocation == false) { /** @var Statistics_IpLocationDao $ipLocation */ $ipLocation = MidasLoader::newDao('IpLocationDao', 'statistics'); $ipLocation->setIp($ip); // we will perform the geolocation later, since it can be slow $ipLocation->setLatitude(''); $ipLocation->setLongitude(''); $ipLocationModel->save($ipLocation); } /** @var Statistics_DownloadDao $download */ $download = MidasLoader::newDao('DownloadDao', 'statistics'); $download->setItemId($item->getKey()); $download->setIpLocationId($ipLocation->getKey()); $download->setDate(date('Y-m-d H:i:s')); $download->setUserAgent($userAgent); if ($user instanceof UserDao) { $download->setUserId($user->getKey()); } $this->save($download); }
/** * Schedule the perform cleanup job. * * @param int $days days to keep partial files * @param string $tempDirectory temporary directory * @param null|UserDao $userDao user scheduling the job */ public function schedulePerformCleanupJob($days, $tempDirectory, $userDao = null) { /** @var Scheduler_JobModel $jobModel */ $jobModel = MidasLoader::loadModel('Job', 'scheduler'); $jobDaos = $jobModel->getJobsByTask('TASK_CLEANUP_PERFORM_CLEANUP'); $cleanupJobDao = false; foreach ($jobDaos as $jobDao) { if ($jobDao->getTask() === 'TASK_CLEANUP_PERFORM_CLEANUP') { $cleanupJobDao = $jobDao; break; } } if ($cleanupJobDao === false) { /** @var Scheduler_JobDao $cleanupJobDao */ $cleanupJobDao = MidasLoader::newDao('JobDao', 'scheduler'); $cleanupJobDao->setTask('TASK_CLEANUP_PERFORM_CLEANUP'); $cleanupJobDao->setPriority(1); $cleanupJobDao->setRunOnlyOnce(0); $cleanupJobDao->setFireTime(date('Y-m-d', strtotime('+1 day' . date('Y-m-d H:i:s'))) . ' 01:00:00'); $cleanupJobDao->setTimeInterval(86400); $cleanupJobDao->setStatus(SCHEDULER_JOB_STATUS_TORUN); if (!is_null($userDao)) { $cleanupJobDao->setCreatorId($userDao->getKey()); } } $cleanupJobDao->setParams(JsonComponent::encode(array('days' => $days, 'tempDirectory' => $tempDirectory))); $jobModel->save($cleanupJobDao); }
/** Post database upgrade. */ public function postUpgrade() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $configPath = LOCAL_CONFIGS_PATH . DIRECTORY_SEPARATOR . $this->moduleName . '.local.ini'; if (file_exists($configPath)) { $config = new Zend_Config_Ini($configPath, 'global'); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_PROVIDER_KEY, MIDAS_THUMBNAILCREATOR_PROVIDER_PHMAGICK, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_FORMAT_KEY, MIDAS_THUMBNAILCREATOR_FORMAT_JPG, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_IMAGE_MAGICK_KEY, $config->get('imagemagick', MIDAS_THUMBNAILCREATOR_IMAGE_MAGICK_DEFAULT_VALUE), $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_KEY, $config->get('useThumbnailer', MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_DEFAULT_VALUE), $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_THUMBNAILER_KEY, $config->get('thumbnailer', MIDAS_THUMBNAILCREATOR_THUMBNAILER_DEFAULT_VALUE), $this->moduleName); $config = new Zend_Config_Ini($configPath, null, true); unset($config->global->imageFormats); unset($config->global->imagemagick); unset($config->global->thumbnailer); unset($config->global->useThumbnailer); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename($configPath); $writer->write(); } else { $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_PROVIDER_KEY, MIDAS_THUMBNAILCREATOR_PROVIDER_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_FORMAT_KEY, MIDAS_THUMBNAILCREATOR_FORMAT_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_IMAGE_MAGICK_KEY, MIDAS_THUMBNAILCREATOR_IMAGE_MAGICK_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_KEY, MIDAS_THUMBNAILCREATOR_USE_THUMBNAILER_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(MIDAS_THUMBNAILCREATOR_THUMBNAILER_KEY, MIDAS_THUMBNAILCREATOR_THUMBNAILER_DEFAULT_VALUE, $this->moduleName); } }
/** test index action */ public function testIndexAction() { /** @var GroupModel $groupModel */ $groupModel = MidasLoader::loadModel('Group'); /** @var ItempolicygroupModel $itempolicygroupModel */ $itempolicygroupModel = MidasLoader::loadModel('Itempolicygroup'); /** @var UserModel $userModel */ $userModel = MidasLoader::loadModel('User'); /** @var FolderModel $folderModel */ $folderModel = MidasLoader::loadModel('Folder'); /** @var UploadComponent $uploadComponent */ $uploadComponent = MidasLoader::loadComponent('Upload'); $usersFile = $this->loadData('User', 'default'); $userDao = $userModel->load($usersFile[0]->getKey()); Zend_Registry::set('notifier', new MIDAS_Notifier(false, null)); $privateFolder = $folderModel->load(1002); $item = $uploadComponent->createUploadedItem($userDao, 'test.png', BASE_PATH . '/tests/testfiles/search.png', $privateFolder, null, '', true); $anonymousGroup = $groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY); $itempolicygroupModel->createPolicy($anonymousGroup, $item, MIDAS_POLICY_READ); $this->params['itemId'] = $item->getKey(); $this->dispatchUrl('/visualize/index/index'); $this->assertController('index'); $this->dispatchUrl('/visualize/image/index'); $this->assertController('image'); $this->dispatchUrl('/visualize/media/index'); $this->assertController('media'); $this->dispatchUrl('/visualize/pdf/index'); $this->assertController('pdf'); $this->dispatchUrl('/visualize/txt/index'); $this->assertController('txt'); $this->dispatchUrl('/visualize/webgl/index'); $this->assertController('webgl'); }
/** Post database upgrade. */ public function postUpgrade() { /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $securityKey = $randomComponent->generateString(32); /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $configPath = LOCAL_CONFIGS_PATH . DIRECTORY_SEPARATOR . $this->moduleName . '.local.ini'; if (file_exists($configPath)) { $config = new Zend_Config_Ini($configPath, 'global'); $settingModel->setConfig(MIDAS_REMOTEPROCESSING_SECURITY_KEY_KEY, $config->get('securitykey', $securityKey), $this->moduleName); $showButton = $config->get('showbutton'); if ($showButton === 'true') { $showButton = 1; } elseif ($showButton === 'false') { $showButton = 0; } else { $showButton = MIDAS_REMOTEPROCESSING_SHOW_BUTTON_DEFAULT_VALUE; } $settingModel->setConfig(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, $showButton, $this->moduleName); $config = new Zend_Config_Ini($configPath, null, true); unset($config->securitykey->securitykey); unset($config->showbutton->showbutton); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename($configPath); $writer->write(); } else { $settingModel->setConfig(MIDAS_REMOTEPROCESSING_SECURITY_KEY_KEY, $securityKey, $this->moduleName); $settingModel->setConfig(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, MIDAS_REMOTEPROCESSING_SHOW_BUTTON_DEFAULT_VALUE, $this->moduleName); } }
/** * Create the database record for inviting a user via email that is not registered yet. * * @param email The email of the user (should not exist in Midas already) * @param group The group to invite the user to * @param inviter The user issuing the invitation (typically the session user) * @return the created NewUserInvitationDao */ public function createInvitation($email, $group, $inviter) { /** @var RandomComponent $randomComponent */ $randomComponent = MidasLoader::loadComponent('Random'); $email = strtolower($email); /** @var NewUserInvitationDao $newUserInvitation */ $newUserInvitation = MidasLoader::newDao('NewUserInvitationDao'); $newUserInvitation->setEmail($email); $newUserInvitation->setAuthKey($randomComponent->generateString(64, '0123456789abcdef')); $newUserInvitation->setInviterId($inviter->getKey()); $newUserInvitation->setGroupId($group->getKey()); $newUserInvitation->setCommunityId($group->getCommunityId()); $newUserInvitation->setDateCreation(date('Y-m-d H:i:s')); /** @var UserModel $userModel */ $userModel = MidasLoader::loadModel('User'); $existingUser = $userModel->getByEmail($email); if ($existingUser) { throw new Zend_Exception('User with that email already exists'); } // If the user has already been sent an invitation to this community, delete existing record $existingInvitation = $this->getByParams(array('email' => $email, 'community_id' => $group->getCommunityId())); if ($existingInvitation) { $this->delete($existingInvitation); } $this->save($newUserInvitation); return $newUserInvitation; }
/** testGetSetValue */ public function testGetSetValue() { Zend_Registry::set('modulesEnable', $this->enabledModules); Zend_Registry::set('notifier', new MIDAS_Notifier(false, null)); /** @var Validation_ScalarResultModel $scalarResultModel */ $scalarResultModel = MidasLoader::loadModel('ScalarResult', 'validation'); $daos = $scalarResultModel->getAll(); $sr = $daos[0]; $folder = new FolderDao(); $folder->setName('result'); $folder->setDescription('result'); $folder->setParentId(-1); $this->Folder->save($folder); $trainingItem = new ItemDao(); $trainingItem->setName('img00.mha'); $trainingItem->setDescription('training img 00'); $trainingItem->setType(0); $this->Item->save($trainingItem); $scalarResultModel->setFolder($sr, $folder); $scalarResultModel->setItem($sr, $trainingItem); $sr->setValue(90.009); $scalarResultModel->save($sr); $daos = $scalarResultModel->getAll(); $sr = $daos[0]; $this->assertEquals(90.009, $sr->getValue()); }
/** * Search all the results. * * @param UserDao $userDao * @param string $search * @param string $order * @return array */ public function searchAll($userDao, $search, $order) { /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); /** @var FolderModel $folderModel */ $folderModel = MidasLoader::loadModel('Folder'); /** @var CommunityModel $communityModel */ $communityModel = MidasLoader::loadModel('Community'); /** @var UserModel $userModel */ $userModel = MidasLoader::loadModel('User'); $ItemsDao = $itemModel->getItemsFromSearch($search, $userDao, 200, false, $order); // Search for the folders $FoldersDao = $folderModel->getFoldersFromSearch($search, $userDao, 15, false, $order); // Search for the communities $CommunitiesDao = $communityModel->getCommunitiesFromSearch($search, $userDao, 15, false, $order); // Search for the users $UsersDao = $userModel->getUsersFromSearch($search, $userDao, 15, false, $order); $return = array(); $return['nitems'] = count($ItemsDao); $return['nfolders'] = count($FoldersDao); $return['ncommunities'] = count($CommunitiesDao); $return['nusers'] = count($UsersDao); $return['results'] = $this->_formatResults($order, $ItemsDao, $FoldersDao, $CommunitiesDao, $UsersDao); return $return; }
/** Post database install. */ public function postInstall() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $settingModel->setConfig(GOOGLE_AUTH_CLIENT_ID_KEY, GOOGLE_AUTH_CLIENT_ID_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(GOOGLE_AUTH_CLIENT_SECRET_KEY, GOOGLE_AUTH_CLIENT_SECRET_DEFAULT_VALUE, $this->moduleName); }
/** * Add a metadata to an itemRevision, updating the value if the row * already exists. * * @return MetadataDao */ public function addMetadataValue($itemRevisionDao, $type, $element, $qualifier, $value, $passItemMetadataChanged = true) { if (!$itemRevisionDao instanceof $itemRevisionDao) { throw new Zend_Exception('Error in itemRevisionDao when adding metadata value.'); } // Gets the metadata $metadataDao = $this->getMetadata($type, $element, $qualifier); if (!$metadataDao) { throw new Zend_Exception('Metadata ' . $element . '.' . $qualifier . " doesn't exist.\n You should add it before adding a value."); } $metadataDao->setItemrevisionId($itemRevisionDao->getKey()); $metadataDao->setValue($value); $item = $itemRevisionDao->getItem(); /** @var ItemModel $itemModel */ $itemModel = MidasLoader::loadModel('Item'); $lastrevision = $itemModel->getLastRevision($item); if ($lastrevision === false) { throw new Zend_Exception('The item must have at least one revision to have metadata', MIDAS_INVALID_POLICY); } // refresh zend search index if latest revision has changed if ($lastrevision->getKey() == $itemRevisionDao->getKey()) { $itemModel->save($item, $passItemMetadataChanged); } $this->saveMetadataValue($metadataDao); return $metadataDao; }
/** Post database upgrade. */ public function postUpgrade() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $config = new Zend_Config_Ini(APPLICATION_CONFIG, 'global'); $settingModel->setConfig('address_verification', $config->get('verifyemail', 0), 'mail'); if ($config->get('smtpfromaddress')) { $fromAddress = $config->get('smtpfromaddress'); } elseif (ini_get('sendmail_from')) { $fromAddress = ini_get('sendmail_from'); } else { $fromAddress = '*****@*****.**'; // RFC2606 } $settingModel->setConfig('from_address', $fromAddress, 'mail'); if ($config->get('smtpserver')) { $components = parse_url($config->get('smtpserver')); if (isset($components['host'])) { $settingModel->setConfig('smtp_host', $components['host'], 'mail'); } if (isset($components['port'])) { $settingModel->setConfig('smtp_port', $components['port'], 'mail'); if ($components['port'] === 587) { $settingModel->setConfig('smtp_use_ssl', 1, 'mail'); } } if (isset($components['user'])) { $settingModel->setConfig('smtp_username', $components['user'], 'mail'); } if (isset($components['pass'])) { $settingModel->setConfig('smtp_password', $components['pass'], 'mail'); } } if ($config->get('smtpuser')) { $settingModel->setConfig('smtp_username', $config->get('smtpuser'), 'mail'); } if ($config->get('smtppassword')) { $settingModel->setConfig('smtp_password', $config->get('smtppassword'), 'mail'); } if ($settingModel->getValueByName('smtp_host', 'mail')) { $provider = 'smtp'; } else { $provider = 'mail'; } $settingModel->setConfig('provider', $provider, 'mail'); /** @var UtilityComponent $utilityComponent */ $utilityComponent = MidasLoader::loadComponent('Utility'); $utilityComponent->installModule('mail'); $config = new Zend_Config_Ini(APPLICATION_CONFIG, null, true); unset($config->global->smtpfromaddress); unset($config->global->smtpserver); unset($config->global->smtpuser); unset($config->global->smtppassword); unset($config->global->verifyemail); $writer = new Zend_Config_Writer_Ini(); $writer->setConfig($config); $writer->setFilename(APPLICATION_CONFIG); $writer->write(); }
/** Post database install. */ public function postInstall() { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $settingModel->setConfig(OAI_REPOSITORY_IDENTIFIER_KEY, OAI_REPOSITORY_IDENTIFIER_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(OAI_REPOSITORY_NAME_KEY, OAI_REPOSITORY_NAME_DEFAULT_VALUE, $this->moduleName); $settingModel->setConfig(OAI_ADMIN_EMAIL_KEY, OAI_ADMIN_EMAIL_DEFAULT_VALUE, $this->moduleName); }
/** * Register an item. * * @param string $item_id * @return Dicomserver_RegistrationDao */ public function createRegistration($item_id) { /** @var Dicomserver_RegistrationDao $registrationDao */ $registrationDao = MidasLoader::newDao('RegistrationDao', 'dicomserver'); $registrationDao->setItemId($item_id); $this->save($registrationDao); return $registrationDao; }