public function createRecord(ContentTypeDefinition $contentTypeDefinition, $properties = [], $viewName = "default", $workspace = "default", $language = "default")
 {
     $classname = $this->getRecordClassForContentType($contentTypeDefinition->getName());
     /** @var Record $record */
     $record = new $classname($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;
 }
Exemplo n.º 2
0
 public function getContentTypeName()
 {
     return $this->dataTypeDefinition->getName();
 }
    public function refreshContentTypeTableStructure($repositoryName, ContentTypeDefinition $contentTypeDefinition)
    {
        $this->refreshInfoTablesStructure();
        $contentTypeName = $contentTypeDefinition->getName();
        $tableName = $repositoryName . '$' . $contentTypeName;
        if ($tableName != Util::generateValidIdentifier($repositoryName) . '$' . Util::generateValidIdentifier($contentTypeName)) {
            throw new \Exception('Invalid repository and/or content type name(s).', self::INVALID_NAMES);
        }
        /** @var PDO $db */
        $dbh = $this->app['db']->getConnection();
        $sql = 'Show Tables Like ?';
        $stmt = $dbh->prepare($sql);
        $stmt->execute(array($tableName));
        if ($stmt->rowCount() == 0) {
            $sql = <<<TEMPLATE_CONTENTTABLE

        CREATE TABLE %s (
          `id` int(11) unsigned NOT NULL,
          `hash` varchar(32) NOT NULL,
          `property_name` varchar(255) DEFAULT NULL,
          `workspace` varchar(255) NOT NULL DEFAULT 'default',
          `language` varchar(255) NOT NULL DEFAULT 'default',
          `property_subtype` varchar(255) DEFAULT NULL,
          `property_status` varchar(255) DEFAULT '1',
          `parent_id` int(11) DEFAULT NULL,
          `position` int(11) DEFAULT NULL,
          `position_left` int(11) DEFAULT NULL,
          `position_right` int(11) DEFAULT NULL,
          `position_level` int(11) DEFAULT NULL,
          `revision` int(11) DEFAULT NULL,
          `deleted` tinyint(1) DEFAULT '0',
          `creation_timestamp` int(11) DEFAULT NULL,
          `creation_apiuser` varchar(255) DEFAULT NULL,
          `creation_clientip` varchar(255) DEFAULT NULL,
          `creation_username` varchar(255) DEFAULT NULL,
          `creation_firstname` varchar(255) DEFAULT NULL,
          `creation_lastname` varchar(255) DEFAULT NULL,
          `lastchange_timestamp` int(11) DEFAULT NULL,
          `lastchange_apiuser` varchar(255) DEFAULT NULL,
          `lastchange_clientip` varchar(255) DEFAULT NULL,
          `lastchange_username` varchar(255) DEFAULT NULL,
          `lastchange_firstname` varchar(255) DEFAULT NULL,
          `lastchange_lastname` varchar(255) DEFAULT NULL,
          `validfrom_timestamp` varchar(16) DEFAULT NULL,
          `validuntil_timestamp` varchar(16) DEFAULT NULL,
          KEY `id` (`id`),
          KEY `workspace` (`workspace`,`language`),
          KEY `validfrom_timestamp` (`validfrom_timestamp`,`validuntil_timestamp`,`id`,`deleted`)

         ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

TEMPLATE_CONTENTTABLE;
            $sql = sprintf($sql, $tableName);
            $stmt = $dbh->prepare($sql);
            try {
                $stmt->execute();
            } catch (\PDOException $e) {
                return false;
            }
        }
        $sql = sprintf('DESCRIBE %s', $tableName);
        $stmt = $dbh->prepare($sql);
        $stmt->execute();
        $fields = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
        $properties = array();
        foreach ($contentTypeDefinition->getProperties() as $property) {
            $properties[] = 'property_' . $property;
        }
        $newfields = array();
        foreach (array_diff($properties, $fields) as $field) {
            $newfields[] = 'ADD COLUMN `' . $field . '` LONGTEXT';
        }
        if (count($newfields) != 0) {
            $sql = sprintf('ALTER TABLE %s', $tableName);
            $sql .= ' ' . join($newfields, ',');
            $stmt = $dbh->prepare($sql);
            $stmt->execute();
        }
        return true;
    }