/** * Create screenshot * * @param Entity\Service $service * @param array $params * @return \Entity\Webshot */ public function createScreen(Entity\Service $service, array $data) { if (false === $this->checkSignKey($data, $service->getSecretKey())) { throw new Extlib\Exception(translate('Invalid key signature requests.'), Response::CODE_UNAUTHORIZED); } if (false === $this->checkService($service)) { throw new Extlib\Exception(sprintf(translate("Service '% s' has exhausted the limit - '% s' discharges on the day.", Response::CODE_NOT_ACCEPTABLE), $service->getName(), $service->getWebshotsPerDay()), Extlib\Http\Response::CODE_FORBIDDEN); } $output = $this->getOutputData(); $params = $this->prepareParams($data); $params['out'] = $output->filePath; $return = 0; $out = array(); $command = sprintf("%s %s %s %s", $this->config->system->xvfb->path, $this->getXvfbConfig(), $this->config->system->cutycapt->path, $this->getParamsAsString($params)); //>/home/mart/logs/webshot.log 2>&1 $this->log($command); $this->getEm()->beginTransaction(); try { $exec = exec($command, $out, $return); if (0 !== $return || false === file_exists($output->filePath)) { throw new Extlib\Exception(translate("An error occurred while performing command: '%s'."), $command); } $file = new \Entity\File(); $file->setFilePath($output->relativePath); $this->getEm()->persist($file); $webshot = new \Entity\Webshot(); $webshot->setUrl($params['url']); $webshot->setImage($file); $this->getEm()->persist($webshot); $service->addWebshot($webshot); $this->getEm()->flush(); $this->getEm()->commit(); } catch (\Exception $exc) { $this->getEm()->rollback(); Extlib\FileManager::removeFile($output->filePath); throw new Extlib\Exception(translate('An error occurred while creating the dump.'), Response::CODE_INTERNAL_SERVER_ERROR, $exc); } return $webshot; }
private function toArrayFromModel(Disk\Internals\Model $model) { $entity = null; if ($model instanceof Disk\Storage) { $entity = new Entity\Storage(); } elseif ($model instanceof Disk\File) { $entity = new Entity\Folder(); } elseif ($model instanceof Disk\Folder) { $entity = new Entity\File(); } else { throw new RestException('Unknown object ' . get_class($model)); } $toArray = array_intersect_key($model->toArray(), $entity->getFieldsForShow()); foreach ($entity->getFieldsForMap() as $fieldName => $modifiers) { if (!isset($toArray[$fieldName])) { continue; } $toArray[$fieldName] = call_user_func_array($modifiers['OUT'], array($toArray[$fieldName])); } unset($fieldName, $modifiers); if ($model instanceof Disk\File) { $toArray['DOWNLOAD_URL'] = $this->host . $this->urlManager->getUrlForDownloadFile($model) . '&auth=' . $this->restServer->getAuth(); if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) { $toArray['DETAIL_URL'] = null; } else { $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathFileDetail($model); } } elseif ($model instanceof Disk\Folder) { if ($model->getStorage()->getProxyType() instanceof Disk\ProxyType\RestApp) { $toArray['DETAIL_URL'] = null; } else { $toArray['DETAIL_URL'] = $this->host . $this->urlManager->getPathInListing($model) . $model->getName(); } } return $toArray; }
public function send_file($fid, $email) { $rfile = $this->ci->doctrine->em->getRepository('Entity\\File')->find($fid); if (!$rfile) { return -1; } $teacher = $this->ci->doctrine->em->getRepository('Entity\\Teacher')->findOneByEmail($email); if (!$teacher) { return -1; } $file = new \Entity\File(); $file->setName($rfile->getName()); $file->setData($rfile->getData()); $file->setType($rfile->getType()); $file->setResp($teacher); $this->ci->doctrine->em->persist($file); $this->ci->doctrine->em->flush(); return 1; }