public function execute() { $this->params = $this->extractRequestParams(); // Extract the file and archiveName from the request parameters $this->validateParameters(); // Check whether we're allowed to revert this file $this->checkPermissions($this->getUser()); $sourceUrl = $this->file->getArchiveVirtualUrl($this->archiveName); $status = $this->file->upload($sourceUrl, $this->params['comment'], $this->params['comment'], 0, false, false, $this->getUser()); if ($status->isGood()) { $result = array('result' => 'Success'); } else { $result = array('result' => 'Failure', 'errors' => $this->getResult()->convertStatusToArray($status)); } $this->getResult()->addValue(null, $this->getModuleName(), $result); }
/** * @return array */ protected function getHashes() { $hashes = array(); list($oldRels, $deleteCurrent) = $this->getOldRels(); if ($deleteCurrent) { $hashes['.'] = $this->file->getSha1(); } if (count($oldRels)) { $dbw = $this->file->repo->getMasterDB(); $res = $dbw->select('oldimage', array('oi_archive_name', 'oi_sha1'), array('oi_archive_name' => array_keys($oldRels)), __METHOD__); foreach ($res as $row) { if (rtrim($row->oi_sha1, "") === '') { // Get the hash from the file $oldUrl = $this->file->getArchiveVirtualUrl($row->oi_archive_name); $props = $this->file->repo->getFileProps($oldUrl); if ($props['fileExists']) { // Upgrade the oldimage row $dbw->update('oldimage', array('oi_sha1' => $props['sha1']), array('oi_name' => $this->file->getName(), 'oi_archive_name' => $row->oi_archive_name), __METHOD__); $hashes[$row->oi_archive_name] = $props['sha1']; } else { $hashes[$row->oi_archive_name] = false; } } else { $hashes[$row->oi_archive_name] = $row->oi_sha1; } } } $missing = array_diff_key($this->srcRels, $hashes); foreach ($missing as $name => $rel) { $this->status->error('filedelete-old-unregistered', $name); } foreach ($hashes as $name => $hash) { if (!$hash) { $this->status->error('filedelete-missing', $this->srcRels[$name]); unset($hashes[$name]); } } return $hashes; }