public function start()
{
$env = $this->Environment();
$log = $this->log();
$args = array('dataTransferID' => $this->ID, 'logfile' => $this->logfile(), 'backupBeforePush' => $this->backupBeforePush);
if (!$this->AuthorID) {
$this->AuthorID = Member::currentUserID();
}
if ($this->AuthorID) {
$author = $this->Author();
$message = sprintf('Data transfer on %s (%s, %s) initiated by %s (%s), with IP address %s', $env->getFullName(), $this->Direction, $this->Mode, $author->getName(), $author->Email, Controller::curr()->getRequest()->getIP());
$log->write($message);
}
$token = Resque::enqueue('snapshot', 'DataTransferJob', $args, true);
$this->ResqueToken = $token;
$this->write();
$message = sprintf('Data transfer queued as job %s', $token);
$log->write($message);
}
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()); }