/** * If this file is attached to a {@link DNDataArchive}, then we need to check security permissions, to ensure the * currently logged in {@link Member} can download the file. * * This uses the secureassets module to provide the security of these assets. */ public function canDownload() { $member = Member::currentUser(); $file = $this->owner; $archive = DNDataArchive::get()->filter('ArchiveFileID', $file->ID)->First(); if ($archive) { return $archive->canDownload($member); } return true; // By default, files can be downloaded from assets/ normally }
/** * @param array $data * @param Form $form * * @return bool|SS_HTTPResponse * @throws SS_HTTPResponse_Exception * @throws ValidationException * @throws null */ public function doMove($data, Form $form) { $this->setCurrentActionType(self::ACTION_SNAPSHOT); // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return $this->project404Response(); } /** @var DNDataArchive $dataArchive */ $dataArchive = DNDataArchive::get()->byId($data['DataArchiveID']); if (!$dataArchive) { throw new LogicException('Invalid data archive'); } // We check for canDownload because that implies access to the data. if (!$dataArchive->canDownload()) { throw new SS_HTTPResponse_Exception('Not allowed to access archive', 403); } // Validate $data['EnvironmentID'] by checking against $validEnvs. $validEnvs = $dataArchive->validTargetEnvironments(); $environment = $validEnvs->find('ID', $data['EnvironmentID']); if (!$environment) { throw new LogicException('Invalid environment'); } $dataArchive->EnvironmentID = $environment->ID; $dataArchive->write(); return $this->redirectBack(); }
public function DataArchives() { $envIds = $this->Environments()->column('ID'); return DNDataArchive::get()->filter('EnvironmentID', $envIds); }
public function run($request) { $args = $request->getVar('args'); $dryRun = $args && in_array('--dry-run', $args); $log = function ($message) { $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; echo $message . PHP_EOL; }; if (!Director::is_cli()) { $log('This task must be run under the command line'); return; } if ($dryRun) { $log('Running in dry-run mode. No data will be deleted'); } $count = 0; foreach (DNEnvironment::get() as $environment) { $project = $environment->Project(); if (!$project || !$project->exists()) { $log(sprintf('Environment (ID %s, Name: %s, Created: %s) is linked to a non-existent project. Deleting', $environment->ID, $environment->Name, $environment->Created)); if (!$dryRun) { $environment->delete(); $environment->destroy(); } $count++; } } foreach (DNDeployment::get() as $deployment) { $environment = $deployment->Environment(); if (!$environment || !$environment->exists()) { $log(sprintf('Deployment (ID %s, Created: %s) is linked to a non-existent environment. Deleting', $deployment->ID, $deployment->Created)); if (!$dryRun) { $deployment->delete(); $deployment->destroy(); } $count++; } } foreach (DNDataTransfer::get() as $transfer) { $environment = $transfer->Environment(); if (!$environment || !$environment->exists()) { $log(sprintf('Data transfer (ID %s, Created: %s) is linked to a non-existent environment. Deleting', $transfer->ID, $transfer->Created)); if (!$dryRun) { $transfer->delete(); $transfer->destroy(); } $count++; } } foreach (DNDataArchive::get() as $archive) { $environment = $archive->Environment(); if (!$environment || !$environment->exists()) { $log(sprintf('Archive (ID %s, Created: %s) is linked to a non-existent environment. Deleting', $archive->ID, $archive->Created)); if (!$dryRun) { $archive->delete(); $archive->destroy(); } $count++; } } foreach (DNGitFetch::get() as $fetch) { $project = $fetch->Project(); if (!$project || !$project->exists()) { $log(sprintf('Git fetch (ID %s, Created: %s) is linked to a non-existent project. Deleting', $fetch->ID, $fetch->Created)); if (!$dryRun) { $fetch->delete(); $fetch->destroy(); } $count++; } } foreach (DNPing::get() as $ping) { $environment = $ping->Environment(); if (!$environment || !$environment->exists()) { $log(sprintf('Ping (ID %s, Created: %s) is linked to a non-existent environment. Deleting', $ping->ID, $ping->Created)); if (!$dryRun) { $ping->delete(); $ping->destroy(); } $count++; } } $log(sprintf('Finished. Processed %s records', $count)); }
public function doMove($data, $form) { // Performs canView permission check by limiting visible projects $project = $this->getCurrentProject(); if (!$project) { return new SS_HTTPResponse("Project '" . Convert::raw2xml($this->getRequest()->latestParam('Project')) . "' not found.", 404); } $dataArchive = null; $dataArchive = DNDataArchive::get()->byId($data['DataArchiveID']); if (!$dataArchive) { throw new LogicException('Invalid data archive'); } // We check for canDownload because that implies access to the data. if (!$dataArchive->canDownload()) { throw new SS_HTTPResponse_Exception('Not allowed to access archive', 403); } // Validate $data['EnvironmentID'] by checking against $validEnvs. $validEnvs = $dataArchive->validTargetEnvironments(); $environment = $validEnvs->find('ID', $data['EnvironmentID']); if (!$environment) { throw new LogicException('Invalid environment'); } $dataArchive->EnvironmentID = $environment->ID; $dataArchive->write(); $this->redirectBack(); }