Ejemplo n.º 1
0
 /** @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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
 /** 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;
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /** 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;
 }
Ejemplo n.º 9
0
 /** 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);
 }
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /** 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;
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
Ejemplo n.º 13
0
 /**
  * Create a community agreement.
  *
  * @param  string $community_id
  * @param  string $agreement
  * @return Communityagreement_AgreementDao
  */
 public function createAgreement($community_id, $agreement)
 {
     /** @var Communityagreement_AgreementDao $agreementDao */
     $agreementDao = MidasLoader::newDao('AgreementDao', 'communityagreement');
     $agreementDao->setCommunityId($community_id);
     $agreementDao->setAgreement($agreement);
     $this->save($agreementDao);
     return $agreementDao;
 }
Ejemplo n.º 14
0
 /** save logs */
 public function saveLog($jobDao, $text)
 {
     /** @var Scheduler_JobLogDao $joblog */
     $joblog = MidasLoader::newDao('JobLogDao', 'scheduler');
     $joblog->setJobId($jobDao->getKey());
     $joblog->setDate(date('Y-m-d H:i:s'));
     $joblog->setLog($text);
     $this->save($joblog);
 }
Ejemplo n.º 15
0
 /** Create a wallet
  * @return WalletDao
  */
 public function createWallet($userDao, $dollars)
 {
     /** @var Example_WalletDao $wallet */
     $wallet = MidasLoader::newDao('WalletDao', 'example');
     $wallet->setUserId($userDao->getKey());
     $wallet->setDollars($dollars);
     $this->save($wallet);
     return $wallet;
 }
Ejemplo n.º 16
0
 /**
  * Create a new record of a user who authenticates via google auth.
  *
  * @param $user The user dao representing this user's information
  * @param $googlePersonId The unique identifier value for the google user
  * @return The created googleauth_user dao.
  */
 public function createGoogleUser($user, $googlePersonId)
 {
     /** @var Googleauth_UserDao $guserDao */
     $guserDao = MidasLoader::newDao('UserDao', 'googleauth');
     $guserDao->setUserId($user->getKey());
     $guserDao->setGooglePersonId($googlePersonId);
     $this->save($guserDao);
     return $guserDao;
 }
Ejemplo n.º 17
0
 /**
  * Create a temporary token that will be used to fetch the user's real API token later.
  *
  * @param UserDao $user user to create the token for
  * @param TokenDao $tokenDao token DAO
  * @return Mfa_ApitokenDao
  * @throws Zend_Exception
  */
 public function createTempToken($user, $tokenDao)
 {
     /** @var Mfa_ApitokenDao $newToken */
     $newToken = MidasLoader::newDao('ApitokenDao', 'mfa');
     $newToken->setUserId($user->getKey());
     $newToken->setTokenId($tokenDao->getKey());
     $newToken->setCreationDate(date('Y-m-d H:i:s'));
     $this->save($newToken);
     return $newToken;
 }
Ejemplo n.º 18
0
 /** Add a comment to an item */
 public function addComment($user, $item, $comment)
 {
     /** @var Comments_ItemcommentDao $commentDao */
     $commentDao = MidasLoader::newDao('ItemcommentDao', 'comments');
     $commentDao->setUserId($user->getKey());
     $commentDao->setItemId($item->getKey());
     $commentDao->setComment($comment);
     $this->save($commentDao);
     Zend_Registry::get('notifier')->callback('CALLBACK_COMMENTS_ADDED_COMMENT', array('comment' => $commentDao));
 }
Ejemplo n.º 19
0
 /**
  * Enable or disable the community as a package-hosting project.
  *
  * @param community The community dao
  * @param $value Boolean value for whether or not the community is a package-hosting project
  */
 public function setEnabled($community, $value)
 {
     $project = $this->getByCommunityId($community->getKey());
     if (!$project) {
         /** @var Packages_ProjectDao $project */
         $project = MidasLoader::newDao('ProjectDao', $this->moduleName);
         $project->setCommunityId($community->getKey());
     }
     $project->setEnabled($value ? 1 : 0);
     $this->save($project);
 }
Ejemplo n.º 20
0
 /**
  * Create a new progress record beginning with the current value equal to 0.
  *
  * @param int $max maximum value of the progress (default is 0 for indeterminate)
  * @param string $message initial progress message (default is empty)
  * @return ProgressDao progress DAO
  */
 public function createProgress($max = 0, $message = '')
 {
     /** @var ProgressDao $progress */
     $progress = MidasLoader::newDao('ProgressDao');
     $progress->setCurrent(0);
     $progress->setMaximum($max);
     $progress->setMessage($message);
     $progress->setDateCreation(date('Y-m-d H:i:s'));
     $progress->setLastUpdate(date('Y-m-d H:i:s'));
     $this->save($progress);
     return $progress;
 }
Ejemplo n.º 21
0
 /**
  * Create a big thumbnail for the given bitstream with the given width. It is used as the main image of the given item and shown in the item view page.
  *
  * @path /thumbnailcreator/item/bigthumbnail/{id}
  * @http PUT
  * @param bitstreamId The bitstream to create the thumbnail from
  * @param id The item to set the thumbnail on
  * @param width (Optional) The width in pixels to resize to (aspect ratio will be preserved). Defaults to 575
  * @return The ItemthumbnailDao object that was created
  *
  * @param array $args parameters
  * @throws Exception
  */
 public function createBigThumbnail($args)
 {
     /** @var ApihelperComponent $apihelperComponent */
     $apihelperComponent = MidasLoader::loadComponent('Apihelper');
     $apihelperComponent->renameParamKey($args, 'itemId', 'id', false);
     $apihelperComponent->validateParams($args, array('id'));
     /** @var Thumbnailcreator_ImagemagickComponent $imComponent */
     $imComponent = MidasLoader::loadComponent('Imagemagick', 'thumbnailcreator');
     /** @var AuthenticationComponent $authComponent */
     $authComponent = MidasLoader::loadComponent('Authentication');
     $userDao = $authComponent->getUser($args, Zend_Registry::get('userSession')->Dao);
     $itemId = $args['id'];
     $bitstreamId = $args['bitstreamId'];
     $width = '575';
     if (isset($args['width'])) {
         $width = $args['width'];
     }
     /** @var BitstreamModel $bitstreamModel */
     $bitstreamModel = MidasLoader::loadModel('Bitstream');
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     /** @var Thumbnailcreator_ItemthumbnailModel $itemthumbnailModel */
     $itemthumbnailModel = MidasLoader::loadModel('Itemthumbnail', 'thumbnailcreator');
     $bitstream = $bitstreamModel->load($bitstreamId);
     $item = $itemModel->load($itemId);
     if (!$itemModel->policyCheck($item, $userDao, MIDAS_POLICY_WRITE)) {
         throw new Exception('You didn\'t log in or you don\'t have the write permission for the given item.', MIDAS_INVALID_POLICY);
     }
     $itemThumbnail = $itemthumbnailModel->getByItemId($item->getKey());
     if (!$itemThumbnail) {
         /** @var Thumbnailcreator_ItemthumbnailDao $itemThumbnail */
         $itemThumbnail = MidasLoader::newDao('ItemthumbnailDao', 'thumbnailcreator');
         $itemThumbnail->setItemId($item->getKey());
     } else {
         $oldThumb = $bitstreamModel->load($itemThumbnail->getThumbnailId());
         $bitstreamModel->delete($oldThumb);
     }
     try {
         $thumbnail = $imComponent->createThumbnailFromPath($bitstream->getName(), $bitstream->getFullPath(), (int) $width, 0, false);
         if (!file_exists($thumbnail)) {
             throw new Exception('Could not create thumbnail from the bitstream', MIDAS_INTERNAL_ERROR);
         }
         /** @var AssetstoreModel $assetstoreModel */
         $assetstoreModel = MidasLoader::loadModel('Assetstore');
         $thumb = $bitstreamModel->createThumbnail($assetstoreModel->getDefault(), $thumbnail);
         $itemThumbnail->setThumbnailId($thumb->getKey());
         $itemthumbnailModel->save($itemThumbnail);
         return $itemThumbnail->toArray();
     } catch (Exception $e) {
         throw new Exception($e->getMessage(), MIDAS_INTERNAL_ERROR);
     }
 }
Ejemplo n.º 22
0
 /**
  * Create an item metric.
  *
  * @param string $metricName
  * @param string $bmsName
  * @return Batchmake_ItemmetricDao
  * @throws Zend_Exception  if an item metric already exists with this metric name
  */
 public function createItemmetric($metricName, $bmsName)
 {
     /** @var Batchmake_ItemmetricDao $itemmetric */
     $itemmetric = MidasLoader::newDao('ItemmetricDao', 'batchmake');
     // make sure one isn't already there by this name
     $found = $this->findBy('metric_name', $metricName);
     if (isset($found) && count($found) > 0) {
         // don't allow the creation, as we have a metric of this name already
         throw new Zend_Exception('An Itemmetric already exists with that name');
     }
     $itemmetric->setMetricName($metricName);
     $itemmetric->setBmsName($bmsName);
     $this->save($itemmetric);
     return $itemmetric;
 }
Ejemplo n.º 23
0
 /**
  * Create a new ldap user and an underlying core user entry.
  *
  * @param ldapLogin What the user uses to actually login to the ldap
  * @param email The user's email (because it might be different from ldap login)
  * @param password The user's password (not stored, just used to generate initial default api key)
  * @param firstName User's first name
  * @param lastName User's last name
  * @return The ldap user dao that was created
  */
 public function createLdapUser($ldapLogin, $email, $password, $firstName, $lastName)
 {
     /** @var UserModel $userModel */
     $userModel = MidasLoader::loadModel('User');
     $userDao = $userModel->createUser($email, $password, $firstName, $lastName);
     $userDao->setSalt('x');
     // place invalid salt so normal authentication will fail
     $userModel->save($userDao);
     /** @var Ldap_UserDao $ldapUserDao */
     $ldapUserDao = MidasLoader::newDao('UserDao', 'ldap');
     $ldapUserDao->setUserId($userDao->getKey());
     $ldapUserDao->setLogin($ldapLogin);
     $this->save($ldapUserDao);
     return $ldapUserDao;
 }
Ejemplo n.º 24
0
 /** Add a metadata
  * @return MetadataDao
  */
 public function addMetadata($type, $element, $qualifier, $description = null)
 {
     // Gets the metadata
     $metadata = $this->getMetadata($type, $element, $qualifier);
     if ($metadata) {
         throw new Zend_Exception('Metadata already exists.');
     }
     /** @var MetadataDao $metadataDao */
     $metadataDao = MidasLoader::newDao('MetadataDao');
     $metadataDao->setMetadatatype($type);
     $metadataDao->setElement($element);
     $metadataDao->setQualifier($qualifier);
     $this->save($metadataDao);
     return $metadataDao;
 }
Ejemplo n.º 25
0
 /** Index action */
 public function indexAction()
 {
     $this->requireAdminPrivileges();
     $this->view->pageTitle = 'Landing Page Module Configuration';
     $form = new Landingpage_Form_Admin();
     $textDaos = $this->Landingpage_Text->getAll();
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         if ($form->isValid($data)) {
             $values = $form->getValues();
             if (count($textDaos) > 0) {
                 $textDao = $textDaos[0];
             } else {
                 /** @var Landingpage_TextDao $textDao */
                 $textDao = MidasLoader::newDao('Text', $this->moduleName);
             }
             $textDao->setText($values[LANDINGPAGE_TEXT_KEY]);
             $this->Landingpage_Text->save($textDao);
             unset($values[LANDINGPAGE_TEXT_KEY]);
             foreach ($values as $key => $value) {
                 if ($key !== 'csrf' && !is_null($value)) {
                     $this->Setting->setConfig($key, $value, $this->moduleName);
                 }
             }
         }
         $form->populate($data);
     } else {
         $elements = $form->getElements();
         foreach ($elements as $element) {
             $name = $element->getName();
             if ($name === LANDINGPAGE_TEXT_KEY) {
                 if (count($textDaos) > 0) {
                     $value = $textDaos[0]->getText();
                     $form->setDefault($name, $value);
                 }
             } elseif ($name !== 'csrf' && $name !== 'submit') {
                 $value = $this->Setting->getValueByName($name, $this->moduleName);
                 if (!is_null($value)) {
                     $form->setDefault($name, $value);
                 }
             }
         }
     }
     $this->view->form = $form;
     session_start();
 }
Ejemplo n.º 26
0
 /**
  * Create a task.
  *
  * @param UserDao $userDao
  * @param string $tmpWorkDirRoot
  * @return Batchmake_TaskDao
  * @throws Zend_Exception
  */
 public function createTask($userDao, $tmpWorkDirRoot)
 {
     if (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Error parameters.');
     }
     /** @var Batchmake_TaskDao $task */
     $task = MidasLoader::newDao('TaskDao', 'batchmake');
     $task->setUserId($userDao->getKey());
     $this->save($task);
     $userId = $task->getUserId();
     $taskId = $task->getKey();
     $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId);
     // create a workDir based on the task and user
     $workDir = KWUtils::createSubDirectories($tmpWorkDirRoot . '/', $subdirs);
     $task->setWorkDir($workDir);
     $this->save($task);
     return $task;
 }
 /**
  * Add scheduled tasks for notifying users that a threshold was crossed.
  *
  * @param Tracker_ScalarDao $scalarDao scalar DAO
  * @param array $thresholdNotificationDaos threshold notification DAOs
  */
 public function scheduleNotifications($scalarDao, $thresholdNotificationDaos)
 {
     /** @var Scheduler_JobModel $jobModel */
     $jobModel = MidasLoader::loadModel('Job', 'scheduler');
     /** @var Tracker_ThresholdNotificationDao $thresholdNotificationDao */
     foreach ($thresholdNotificationDaos as $thresholdNotificationDao) {
         /** @var Scheduler_JobDao $jobDao */
         $jobDao = MidasLoader::newDao('JobDao', 'scheduler');
         $jobDao->setTask('TASK_TRACKER_SEND_THRESHOLD_NOTIFICATION');
         $jobDao->setPriority(1);
         $jobDao->setRunOnlyOnce(1);
         $jobDao->setFireTime(date('Y-m-d H:i:s'));
         $jobDao->setTimeInterval(0);
         $jobDao->setStatus(SCHEDULER_JOB_STATUS_TORUN);
         $jobDao->setCreatorId($thresholdNotificationDao->getRecipientId());
         $jobDao->setParams(JsonComponent::encode(array('notification' => $thresholdNotificationDao, 'scalar' => $scalarDao)));
         $jobModel->save($jobDao);
     }
 }
Ejemplo n.º 28
0
 /**
  * Create and return a new oauth client owned by the given user.
  *
  * @param UserDao $userDao owner of the client
  * @param string $name human readable name of the client
  * @return Oauth_ClientDao
  * @throws Zend_Exception
  */
 public function create($userDao, $name)
 {
     if (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Invalid userDao');
     }
     if (empty($name)) {
         throw new Zend_Exception('Client name must not be empty');
     }
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     /** @var Oauth_ClientDao $clientDao */
     $clientDao = MidasLoader::newDao('ClientDao', $this->moduleName);
     $clientDao->setName($name);
     $clientDao->setOwnerId($userDao->getKey());
     $clientDao->setSecret($randomComponent->generateString(40));
     $clientDao->setCreationDate(date('Y-m-d H:i:s'));
     $this->save($clientDao);
     return $clientDao;
 }
Ejemplo n.º 29
0
 /**
  * Set the rating on an item for a user (overwrites if already exists)
  * If a 0 rating is passed, any existing rating will be removed.
  */
 public function setRating($user, $item, $rating)
 {
     $row = $this->database->fetchRow($this->database->select()->where('item_id = ?', $item->getKey())->where('user_id = ?', $user->getKey()));
     $dao = $this->initDao('Itemrating', $row, 'ratings');
     if ($dao == null) {
         if ($rating == 0) {
             return;
             // no need to save this rating at all
         }
         /** @var Ratings_ItemratingDao $dao */
         $dao = MidasLoader::newDao('ItemratingDao', 'ratings');
         $dao->setUserId($user->getKey());
         $dao->setItemId($item->getKey());
     } elseif ($rating == 0) {
         $this->delete($dao);
         return;
     }
     $dao->setRating($rating);
     $this->save($dao);
 }
 /**
  * Create an invitation record for the user into the given group.
  *
  * @param GroupDao $groupDao The group to invite the user to
  * @param UserDao $userDao The user performing the invitation (typically the session user)
  * @param UserDao $invitedUserDao The user being invited to the group
  * @return false|CommunityInvitationDao
  * @throws Zend_Exception
  */
 public function createInvitation($groupDao, $userDao, $invitedUserDao)
 {
     $communityDao = $groupDao->getCommunity();
     $invitations = $invitedUserDao->getInvitations();
     foreach ($invitations as $invitation) {
         if ($invitation->getCommunityId() == $communityDao->getKey()) {
             return false;
         }
     }
     /** @var CommunityInvitationDao $invitationDao */
     $invitationDao = MidasLoader::newDao('CommunityInvitationDao');
     $invitationDao->setCommunityId($communityDao->getKey());
     $invitationDao->setGroupId($groupDao->getKey());
     $invitationDao->setUserId($invitedUserDao->getKey());
     $this->save($invitationDao);
     /** @var FeedModel $feedModel */
     $feedModel = MidasLoader::loadModel('Feed');
     /** @var FeedpolicyuserModel $feedpolicyuserModel */
     $feedpolicyuserModel = MidasLoader::loadModel('Feedpolicyuser');
     $feed = $feedModel->createFeed($userDao, MIDAS_FEED_COMMUNITY_INVITATION, $invitationDao, $communityDao);
     $feedpolicyuserModel->createPolicy($invitedUserDao, $feed, MIDAS_POLICY_ADMIN);
     return $invitationDao;
 }