예제 #1
0
 public function doDataTransfer($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);
     }
     $member = Member::currentUser();
     $dataArchive = null;
     // Validate direction.
     if ($data['Direction'] == 'get') {
         $validEnvs = $this->getCurrentProject()->DNEnvironmentList()->filterByCallback(function ($item) {
             return $item->canBackup();
         });
     } else {
         if ($data['Direction'] == 'push') {
             $validEnvs = $this->getCurrentProject()->DNEnvironmentList()->filterByCallback(function ($item) {
                 return $item->canRestore();
             });
         } else {
             throw new LogicException('Invalid direction');
         }
     }
     // Validate $data['EnvironmentID'] by checking against $validEnvs.
     $environment = $validEnvs->find('ID', $data['EnvironmentID']);
     if (!$environment) {
         throw new LogicException('Invalid environment');
     }
     // Validate mode.
     if (!in_array($data['Mode'], array('all', 'assets', 'db'))) {
         throw new LogicException('Invalid mode');
     }
     // Only 'push' direction is allowed an association with an existing archive.
     if ($data['Direction'] == 'push' && isset($data['DataArchiveID']) && is_numeric($data['DataArchiveID'])) {
         $dataArchive = DNDataArchive::get()->byId($data['DataArchiveID']);
         if (!$dataArchive) {
             throw new LogicException('Invalid data archive');
         }
         if (!$dataArchive->canDownload()) {
             throw new SS_HTTPResponse_Exception('Not allowed to access archive', 403);
         }
     }
     $job = new DNDataTransfer();
     $job->EnvironmentID = $environment->ID;
     $job->Direction = $data['Direction'];
     $job->Mode = $data['Mode'];
     $job->DataArchiveID = $dataArchive ? $dataArchive->ID : null;
     $job->write();
     $job->start();
     $this->redirect($job->Link());
 }