public function testAllRecordsStash()
 {
     $record1 = new Record($this->connection->getCurrentContentTypeDefinition(), 'New Record');
     $record1->setID(1);
     $record2 = new Record($this->connection->getCurrentContentTypeDefinition(), 'New Record');
     $record2->setID(2);
     $allRecords = [$record1, $record2];
     $dataDimensions = $this->connection->getCurrentDataDimensions();
     $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertFalse($result);
     $this->invokeMethod($this->connection, 'stashRecord', [$record1, $dataDimensions]);
     $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertFalse($result);
     $this->invokeMethod($this->connection, 'stashAllRecords', [$allRecords, $dataDimensions]);
     $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertTrue($result);
     $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertCount(2, $result);
     $this->invokeMethod($this->connection, 'unStashRecord', ['profiles', 1, $dataDimensions]);
     $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertCount(1, $result);
     $this->invokeMethod($this->connection, 'unStashAllRecords', ['profiles', $dataDimensions]);
     $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertFalse($result);
     $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]);
     $this->assertFalse($result);
 }
 public function match(Record $record)
 {
     $operator = $this->term['operator'];
     $property = Util::generateValidIdentifier($this->term['property']);
     $recordValue = strtolower($record->getProperty($property));
     $conditionValue = strtolower($this->term['value']);
     switch ($operator) {
         case '=':
             return $recordValue == $conditionValue;
             break;
         case '>':
             return $recordValue > $conditionValue;
             break;
         case '<':
             return $recordValue < $conditionValue;
             break;
         case '>=':
             return $recordValue >= $conditionValue;
             break;
         case '<=':
             return $recordValue <= $conditionValue;
             break;
         case '!=':
             return $recordValue != $conditionValue;
             break;
         case '*=':
             $p = strpos($recordValue, $conditionValue);
             if ($p !== false) {
                 return true;
             }
             break;
     }
     return false;
 }
Exemplo n.º 3
0
 public function mapEntity(Record $record, $data)
 {
     $this->data = $data;
     $this->record = $record;
     $this->record->setId($this->data['nid']);
     $this->record->setProperty('name', $this->data['title']);
     $this->record->setRevision(1);
     return $this->record;
 }
 public function getValue(Record $record)
 {
     $key = $record->getProperty($this->getProperty());
     $list = $this->getFormElementDefinition()->getList(1);
     if (array_key_exists($key, $list)) {
         return $list[$key];
     }
     return $key;
 }
 public function testSaveRecordSameConnection()
 {
     $connection = $this->connection;
     $connection->selectContentType('profiles');
     $record = new Record($connection->getCurrentContentTypeDefinition(), 'Agency 5');
     $record->setId(5);
     $this->assertEquals('Agency 5', $record->getProperty('name'));
     $record->setProperty('name', 'Agency 51');
     $connection->saveRecord($record);
     $record = $connection->getRecord(5);
     $this->assertEquals('Agency 51', $record->getProperty('name'));
 }
 public function saveRecord(Record $record, DataDimensions $dataDimensions = null)
 {
     if (!$dataDimensions) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     unset($this->repositoryInfo[(string) $dataDimensions]);
     $url = 'content/' . $record->getContentTypeName() . '/records/' . $dataDimensions->getWorkspace() . '?language=' . $dataDimensions->getLanguage() . '&view=' . $dataDimensions->getViewName() . '&timeshift=' . $dataDimensions->getTimeShift();
     $response = $this->getClient()->post($url, ['body' => ['record' => json_encode($record)]]);
     $id = $response->json();
     $record->setId($id);
     $this->stashRecord($record, $dataDimensions);
     return $response->json();
 }
 public function testSaveRecords()
 {
     $cmdl = $this->connection->getCMDLForContentType('example01');
     $contentTypeDefinition = Parser::parseCMDLString($cmdl);
     $contentTypeDefinition->setName('example01');
     $this->connection->selectContentType('example01');
     for ($i = 1; $i <= 5; $i++) {
         $record = new Record($contentTypeDefinition, 'New Record ' . $i);
         $record->setProperty('article', 'Test ' . $i);
         $id = $this->connection->saveRecord($record);
         $this->assertEquals($i, $id);
     }
 }
 public function testSaveRecordSameConnection()
 {
     $connection = $this->connection;
     if (!$connection) {
         $this->markTestSkipped('RestLike Basic Connection credentials missing.');
     }
     $connection->selectContentType('profiles');
     $record = new Record($connection->getCurrentContentTypeDefinition(), 'Agency 5');
     $record->setId(5);
     $this->assertEquals('Agency 5', $record->getProperty('name'));
     $record->setProperty('name', 'Agency 51');
     $connection->saveRecord($record);
     $record = $connection->getRecord(5);
     $this->assertEquals('Agency 51', $record->getProperty('name'));
 }
 public function saveRecord(Record $record, DataDimensions $dataDimensions = null)
 {
     if (!$dataDimensions) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     unset($this->repositoryInfo[(string) $dataDimensions]);
     $url = 'content/' . $record->getContentTypeName() . '/records/' . $dataDimensions->getWorkspace() . '/' . $dataDimensions->getViewName();
     $record = $record->setLastChangeUserInfo($this->userInfo);
     $this->getClient()->setDefaultOption('query', ['userinfo' => ['username' => $this->userInfo->getUsername(), 'firstname' => $this->userInfo->getFirstname(), 'lastname' => $this->userInfo->getLastname()]]);
     $response = $this->getClient()->post($url, ['body' => ['record' => json_encode($record), 'language' => $dataDimensions->getLanguage()]]);
     $id = $response->json();
     $record->setId($id);
     $this->stashRecord($record, $dataDimensions);
     return $response->json();
 }
 public function saveRecord(Record $record, DataDimensions $dataDimensions = null)
 {
     if (!$dataDimensions) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     if ($record->getID() == '') {
         $record->setId($this->getNextId($record->getContentTypeName(), $dataDimensions));
         $record->setRevision(1);
         $toBeSavedRecord = $record;
     } else {
         $mergedRecord = $this->mergeExistingRecord($record, $dataDimensions);
         $mergedRecord->setRevision($mergedRecord->getRevision() + 1);
         $record->setRevision($mergedRecord->getRevision());
         $toBeSavedRecord = $mergedRecord;
     }
     $toBeSavedRecord->setLastChangeUserInfo($this->userInfo);
     $record->setLastChangeUserInfo($this->userInfo);
     $filename = $this->getConfiguration()->getFolderNameRecords($toBeSavedRecord->getContentTypeName(), $dataDimensions);
     $filename .= '/' . $toBeSavedRecord->getID() . '.json';
     $data = json_encode($toBeSavedRecord, JSON_PRETTY_PRINT);
     $this->stashRecord($toBeSavedRecord, $dataDimensions);
     if (!$this->writeData($filename, $data)) {
         throw new AnyContentClientException('Error when saving record of content type ' . $record->getContentTypeName());
     }
     return $toBeSavedRecord->getID();
 }
 public function getValue(Record $record)
 {
     return $record->getSubtypeLabel();
 }
 public function getValue(Record $record)
 {
     return $record->getStatusLabel();
 }
 public function createRecordFromCMDL($cmdl, $properties = [], $viewName = "default", $workspace = "default", $language = "default")
 {
     $contentTypeDefinition = Parser::parseCMDLString($cmdl);
     /** @var Record $record */
     $record = new Record($contentTypeDefinition, '', $viewName, $workspace, $language);
     $revision = isset($jsonRecord['revision']) ? $jsonRecord['revision'] : 0;
     $record->setRevision($revision);
     if ($this->getOption('validateProperties') == true) {
         foreach ($properties as $property => $value) {
             $record->setProperty($property, $value);
         }
     } else {
         $record->setProperties($properties);
     }
     return $record;
 }
 public function getValue(Record $record)
 {
     return $record->getProperty($this->getProperty());
 }
Exemplo n.º 15
0
 /**
  * remove protected properties and execute @name annotation
  *
  * @param Record $record
  */
 protected function finalizeRecord(Record $record, DataDimensions $dataDimensions)
 {
     // Apply @name annotation
     if ($record->getDataTypeDefinition()->hasNamingPattern()) {
         $record->setName(Util::applyNamingPattern($record->getProperties(), $record->getDataTypeDefinition()->getNamingPattern()));
     }
     // remove protected properties
     $properties = $record->getProperties();
     foreach ($record->getDataTypeDefinition()->getProtectedProperties($dataDimensions->getViewName()) as $property) {
         unset($properties[$property]);
     }
     $record->setProperties($properties);
     return $record;
 }
 protected function mergeExistingRecord(Record $record, DataDimensions $dataDimensions)
 {
     if ($record->getID() != '') {
         $existingRecord = $this->getMultiViewRecord($record->getId(), $record->getContentTypeName(), $dataDimensions);
         if ($existingRecord) {
             $record->setRevision($existingRecord->getRevision());
             $existingProperties = $existingRecord->getProperties();
             $mergedProperties = array_merge($existingProperties, $record->getProperties());
             $mergedRecord = clone $record;
             $mergedRecord->setProperties($mergedProperties);
             return $mergedRecord;
         }
     }
     return $record;
 }
 protected function getDeleteLink(Record $record)
 {
     return $this->getUrlGenerator()->generate('deleteRecord', array('contentTypeAccessHash' => $this->getContext()->getCurrentContentTypeAccessHash(), 'recordId' => $record->getID(), 'workspace' => $this->getContext()->getCurrentWorkspace(), 'language' => $this->getContext()->getCurrentLanguage()));
 }
 public function saveRecord(Record $record, DataDimensions $dataDimensions = null)
 {
     if ($dataDimensions == null) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     $tableName = $this->getContentTypeTableName($record->getContentTypeName());
     $repositoryName = $this->getRepository()->getName();
     $contentTypeName = $record->getContentTypeName();
     $record = $this->finalizeRecord($record, $dataDimensions);
     $definition = $record->getContentTypeDefinition();
     $mode = 'insert';
     $record->setRevision(1);
     $values = [];
     $values['revision'] = 1;
     $values['workspace'] = $dataDimensions->getWorkspace();
     $values['language'] = $dataDimensions->getLanguage();
     $values['deleted'] = 0;
     if ($record->getId() != '') {
         $sql = 'SELECT * FROM ' . $tableName . ' WHERE id = ? AND workspace = ? AND language = ? AND deleted = 0 AND validfrom_timestamp <= ? AND validuntil_timestamp > ?';
         $timestamp = TimeShifter::getTimeshiftTimestamp($dataDimensions->getTimeShift());
         $rows = $this->getDatabase()->fetchAllSQL($sql, [$record->getId(), $dataDimensions->getWorkspace(), $dataDimensions->getLanguage(), $timestamp, $timestamp]);
         if (count($rows) == 1) {
             $values = reset($rows);
             $values['revision'] = $values['revision'] + 1;
             $record->setRevision($values['revision']);
             $mode = 'update';
         }
     }
     if ($mode == 'insert' and $record->getId() == '') {
         // update counter for new record
         $sql = 'INSERT INTO _counter_ (repository,content_type,counter) VALUES (? , ? ,1) ON DUPLICATE KEY UPDATE counter=counter+1;';
         $this->getDatabase()->execute($sql, [$repositoryName, $contentTypeName]);
         $sql = 'SELECT counter FROM _counter_ WHERE repository = ? AND content_type = ?';
         $nextId = $this->getDatabase()->fetchColumnSQL($sql, 0, [$repositoryName, $contentTypeName]);
         $record->setId($nextId);
         // make sure counter is always at least greater than the largest id, e.g. if the counter row got deleted
         $sql = 'SELECT MAX(id)+1 FROM ' . $tableName;
         $nextId = $this->getDatabase()->fetchColumnSQL($sql, 0);
         if ($nextId > $record->getId()) {
             $record->setId($nextId);
             $sql = 'INSERT INTO _counter_ (repository,content_type,counter) VALUES (? , ? ,?) ON DUPLICATE KEY UPDATE counter=?;';
             $this->getDatabase()->execute($sql, [$repositoryName, $contentTypeName, $nextId, $nextId]);
         }
     }
     $values['id'] = $record->getId();
     $timeshiftTimestamp = TimeShifter::getTimeshiftTimestamp();
     if ($mode == 'update') {
         // invalidate current revision
         $sql = 'UPDATE ' . $tableName . ' SET validuntil_timestamp = ? WHERE id = ? AND workspace = ? AND language = ? AND deleted = 0 AND validfrom_timestamp <=? AND validuntil_timestamp >?';
         $params = array();
         $params[] = $timeshiftTimestamp;
         $params[] = $record->getId();
         $params[] = $dataDimensions->getWorkspace();
         $params[] = $dataDimensions->getLanguage();
         $params[] = $timeshiftTimestamp;
         $params[] = $timeshiftTimestamp;
         $this->getDatabase()->execute($sql, $params);
     }
     if ($mode == 'insert') {
         $values['creation_timestamp'] = $timeshiftTimestamp;
         $values['creation_username'] = $this->userInfo->getUsername();
         $values['creation_firstname'] = $this->userInfo->getFirstname();
         $values['creation_lastname'] = $this->userInfo->getLastname();
     }
     $values['lastchange_timestamp'] = $timeshiftTimestamp;
     $values['lastchange_username'] = $this->userInfo->getUsername();
     $values['lastchange_firstname'] = $this->userInfo->getFirstname();
     $values['lastchange_lastname'] = $this->userInfo->getLastname();
     $values['validfrom_timestamp'] = $timeshiftTimestamp;
     $values['validuntil_timestamp'] = TimeShifter::getMaxTimestamp();
     foreach ($definition->getViewDefinition($dataDimensions->getViewName())->getProperties() as $property) {
         $values['property_' . $property] = $record->getProperty($property);
     }
     $values['parent_id'] = $record->getParent();
     $values['position'] = $record->getPosition();
     // TODO: Rebuild Nested Set On Change, but only if not within saveRecords
     //        if ($mode == 'update')
     //        {
     //
     //            $values['parent_id']      = $row['parent_id'];
     //            $values['position']       = $row['position'];
     //            $values['position_left']  = $row['position_left'];
     //            $values['position_right'] = $row['position_right'];
     //            $values['position_level'] = $row['position_level'];
     //
     //        }
     $this->getDatabase()->insert($tableName, $values);
     return $record->getId();
 }
 protected function gotNewerRevision(Repository $repository, Record $record)
 {
     if ($record->getID() != null && $record->getRevision() != null) {
         $records = $this->getRecords($repository);
         if (isset($records[$record->getID()])) {
             /** @var Record $effectiveRecord */
             $effectiveRecord = $records[$record->getID()];
             if ($effectiveRecord->getRevision() > $record->getRevision()) {
                 return true;
             }
         }
     }
     return false;
 }