public function testTree() { if (!($configuration = $this->getConfiguration())) { self::markTestSkipped("No test declaration found"); return; } $dataStore = new DataStore(parent::$container, $configuration); foreach ($dataStore->getTree() as $dataItem) { $this->assertTrue($dataItem->getAttribute($dataStore->getParentField()) == null); $this->assertTrue($dataItem->getAttribute($dataStore->getDriver()->getUniqueId()) > 0); } }
/** * @inheritdoc */ public function httpAction($action) { /** @var $requestService Request */ $configuration = $this->getConfiguration(); $requestService = $this->container->get('request'); $request = json_decode($requestService->getContent(), true); $schemas = $configuration["schemes"]; $debugMode = $configuration['debug'] || $this->container->get('kernel')->getEnvironment() == "dev"; $schemaName = isset($request["schema"]) ? $request["schema"] : $requestService->get("schema"); $defaultCriteria = array('returnType' => 'FeatureCollection', 'maxResults' => 2500); $schema = $schemas[$schemaName]; $schemaConfig = new DataStoreSchemaConfig($schemas[$schemaName]); if (is_array($schemaConfig->dataStore)) { $dataStore = new DataStore($this->container, $schemaConfig->dataStore); } else { throw new \Exception("DataStore setup is not correct"); } $results = array(); switch ($action) { case 'select': foreach ($dataStore->search(array_merge($defaultCriteria, $request)) as $dataItem) { $results[] = $dataItem->toArray(); } break; case 'save': //try { if (!$schemaConfig->allowEdit) { $results["errors"] = array(array('message' => "It is not allowed to edit this data", 'code' => self::ERROR_ACCESS_DENIED)); } $uniqueIdKey = $dataStore->getDriver()->getUniqueId(); if (empty($request['dataItem'][$uniqueIdKey])) { unset($request['dataItem'][$uniqueIdKey]); } $dataItem = $dataStore->create($request['dataItem']); $result = $dataStore->save($dataItem); if (!is_object($result) && isset($result["exception"]) && is_object($result["exception"]) && $result["exception"] instanceof \Exception) { /** @var \Exception $exception */ $exception = $result["exception"]; $results["errors"] = array(array('message' => $exception->getMessage(), 'code' => $exception->getCode())); } $results["dataItem"] = $dataItem->toArray(); //} catch (DBALException $e) { // $message = $debugMode ? $e->getMessage() : "Feature can't be saved. Maybe something is wrong configured or your database isn't available?\n" . // "For more information have a look at the webserver log file. \n Error code: " . $e->getCode(); // $results = array('errors' => array( // array('message' => $message, 'code' => $e->getCode()) // )); //} break; case 'delete': //try { if (!$schemaConfig->allowEdit) { $results["errors"] = array(array('message' => "It is not allowed to edit this data", 'code' => self::ERROR_ACCESS_DENIED)); } $id = intval($request['id']); $results = $dataStore->remove($id); break; case 'file-upload': if (!$schemaConfig->allowEdit) { $results["errors"] = array(array('message' => "It is not allowed to edit this data", 'code' => self::ERROR_ACCESS_DENIED)); } $fieldName = $requestService->get('field'); $urlParameters = array('schema' => $schemaName, 'fid' => $requestService->get('fid'), 'field' => $fieldName); $serverUrl = preg_replace('/\\?.+$/', "", $_SERVER["REQUEST_URI"]) . "?" . http_build_query($urlParameters); $uploadDir = $dataStore->getFilePath($fieldName); $uploadUrl = $dataStore->getFileUrl($fieldName) . "/"; $urlParameters['uploadUrl'] = $uploadUrl; $uploadHandler = new Uploader(array('upload_dir' => $uploadDir . "/", 'script_url' => $serverUrl, 'upload_url' => $uploadUrl, 'accept_file_types' => '/\\.(gif|jpe?g|png)$/i', 'print_response' => false, 'access_control_allow_methods' => array('OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH'))); $results = array_merge($uploadHandler->get_response(), $urlParameters); break; default: $results = array(array('errors' => array(array('message' => $action . " not defined!")))); } return new JsonResponse($results); }