Imports a single project.
We save name, description and parent project.

@param array $project Project info like description or parent project
@param array $parentMapping Array where parent / child relation will be saved
@return int
10315
public function importProject(array $project, array &$parentMapping)
    {
        $this->output('Project "' . $project['name'] . '"');

        $row = $this->existsGerritProject($project['name'], $this->getServerId());

        $projectRow = $project;
        $projectRow['server_id'] = $this->getServerId();

        // If we don`t know this project, save this!
        if ($row === false) {
            $projectRow['parent'] = 0;
            $id = $this->getDatabase()->insertRecord(Database::TABLE_PROJECT, $projectRow);

            $this->output('=> Inserted (ID: ' . $id . ')');

            // If we know this project, lets check if there something new
        } else {

            $this->checkIfServersFirstRun('Projects', 1363893021, $row);

            $id = $row['id'];
            unset($row['id']);

            $diff = array_diff($projectRow, $row);

            // If there some new data for us, update it.
            if (count($diff) > 0) {
                $this->getDatabase()->updateRecord(Database::TABLE_PROJECT, $diff, $id);

                $this->output('=> Updated (ID: ' . $id . ')');

            } else {
                $this->output('=> Nothing new. Skip it');
            }
        }

        // We have to save the parent / child relations of projects to execute bulk updates afterwards
        if (isset($project['parent']) === true) {
            $parentMapping[$project['parent']][] = intval($id);
        }

        return $id;
    }
793944
protected void importRelations(CmsResource resource, Element parentElement) {

        // Get the nodes for the relations
        @SuppressWarnings("unchecked")
        List<Node> relationElements = parentElement.selectNodes(
            "./" + A_CmsImport.N_RELATIONS + "/" + A_CmsImport.N_RELATION);

        List<CmsRelation> relations = new ArrayList<CmsRelation>();
        // iterate over the nodes
        Iterator<Node> itRelations = relationElements.iterator();
        while (itRelations.hasNext()) {
            Element relationElement = (Element)itRelations.next();
            String structureID = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_ID);
            String targetPath = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_PATH);
            String relationType = getChildElementTextValue(relationElement, A_CmsImport.N_RELATION_ATTRIBUTE_TYPE);
            CmsUUID targetId = new CmsUUID(structureID);
            CmsRelationType type = CmsRelationType.valueOf(relationType);

            CmsRelation relation = new CmsRelation(
                resource.getStructureId(),
                resource.getRootPath(),
                targetId,
                targetPath,
                type);

            relations.add(relation);
        }

        if (!relations.isEmpty()) {
            m_importedRelations.put(resource.getRootPath(), relations);
        }
    }
499417
protected function insertRelated(PersistenceContext $context, ParentChildMap $map)
    {
        $primaryKey = $map->getPrimaryKeyColumn();
        /** @var Row[] $parents */
        $parents = [];
        /** @var array $children */
        $children = [];

        foreach ($map->getItems() as $key => $item) {
            $parents[$key]  = $item->getParent();
            $children[$key] = $item->getChild();
        }

        $rows = $this->reference->syncRelated($context, [$this->foreignKeyColumn], $children);

        $selfReferencingChildRows = [];

        foreach ($rows as $key => $row) {
            $parent = $parents[$key];

            if ($parent->hasColumn($primaryKey)) {
                $this->setForeignKey([$row], $this->foreignKeyToParent, $parent->getColumn($primaryKey));
            } else {
                $parent->onInsertPrimaryKey(function ($id) use ($row) {
                    $this->setForeignKey([$row], $this->foreignKeyToParent, $id);
                });

                if ($parent === $row) {
                    $selfReferencingChildRows[] = $row;
                }
            }
        }

        if ($selfReferencingChildRows) {
            // If the rows are self-referencing and need to be inserted
            // an extra step must be taken because the primary key will
            // only be known after inserting so the foreign key to itself
            // will have to be updated separately afterwards
            $context->bulkUpdate(new RowSet($this->relatedTable->withColumnsButIgnoringConstraints([
                $this->relatedPrimaryKey,
                $this->foreignKeyColumn,
            ]), $selfReferencingChildRows));
        }
    }
1265318
public function printDescription(Project $project)
    {
        if ($project->getDescription() !== null) {
            self::$out->write($project->getDescription() . PHP_EOL);
        }
    }
929468
public function getParentMap()
    {
        if (null !== $this->parentMap) {
            return $this->parentMap;
        }

        return $this->parentMap = $this->buildParentMap();
    }
976715
public function createProject(Project $project)
    {
        $request = $this->client->createRequest('POST', '/api/projects', null, array('insight_project' => $project->toArray()));

        return $this->serializer->deserialize(
            (string) $this->send($request)->getBody(),
            'SensioLabs\Insight\Sdk\Model\Project',
            'xml'
        );
    }
967146
public static function loadPivotAttribute(Model $model, Relation $parentRelation = null)
    {
        $attributes = $model->getAttributes();

        foreach ($attributes as $key => $value) {
            if ($key === 'pivot') {
                unset($model[$key]);
                $pivot = $parentRelation->newExistingPivot($value);
                $model->setRelation($key, $pivot);
            }
        }
    }
22568
public function maybeConfigure(Project $project)
    {
        if ($this->proxyConfigured) {
            return;
        }

        $id = null;

        // DataType configured in ProjectConfigurator
        //        if ( is_a($this->wrappedObject, "DataType") )
        //            return;

        if ($this->attributes || (isset($this->characters) && $this->characters != '')) {
            ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project);

            if (isset($this->attributes["id"])) {
                $id = $this->attributes["id"];
            }

            if (isset($this->characters) && $this->characters != '') {
                ProjectConfigurator::addText($project, $this->wrappedObject, (string) $this->characters);
            }
            if ($id !== null) {
                $project->addReference($id, $this->wrappedObject);
            }
        }

        /*if ( is_array($this->children) && !empty($this->children) ) {
            // Configure all child of this object ...
            foreach ($this->children as $child) {
                $child->maybeConfigure($project);
                ProjectConfigurator::storeChild($project, $this->wrappedObject, $child->wrappedObject, strtolower($child->getElementTag()));
            }
        }*/

        $this->proxyConfigured = true;
    }
1289507
public static function storeChild($project, $parent, $child, $tag)
    {
        $ih = IntrospectionHelper::getHelper(get_class($parent));
        $ih->storeElement($project, $parent, $child, $tag);
    }
113631
public static function translatePath(Project $project, $source)
    {
        $result = [];
        if ($source == null) {
            return "";
        }

        $tok = new PathTokenizer($source);
        while ($tok->hasMoreTokens()) {
            $pathElement = $tok->nextToken();
            try {
                $element = self::resolveFile($project, $pathElement);
                for ($i = 0, $_i = strlen($element); $i < $_i; $i++) {
                    self::translateFileSep($element, $i);
                }
                $result[] = $element;
            } catch (BuildException $e) {
                $project->log(
                    "Dropping path element " . $pathElement
                    . " as it is not valid relative to the project",
                    Project::MSG_VERBOSE
                );
            }
        }

        return $result;
    }
1045532
public function createProjectByInput(InputInterface $input) : Project
    {
        $configFinder = new ConfigFinder();
        $configLoader = new ConfigLoader();

        /**
         * This section is just for finding the right values to work with in
         * this execution.
         *
         * $options array will have, after this block, all these values
         */
        $configPath = rtrim($input->getOption('config'), DIRECTORY_SEPARATOR);
        $configValues = $configLoader->loadConfigValues(
            $configFinder->findConfigFile($configPath)
        );

        $masterLanguage = $configValues['master_language'];
        $languages = $configValues['languages'];
        $filePaths = $configValues['paths'];

        return Project::create(
            $masterLanguage,
            $languages,
            $filePaths
        );
    }
923684
private function mapsController($controller, $uriapp = NULL, $method = NULL, $parentController = NULL){
        $httpMethod= isset($controller['httpMethod']) ? $controller['httpMethod'] : '*';
        if($parentController != NULL){
            $controller['url']= rtrim($parentController['url'], '/') . '/' . ltrim($controller['url'], '/');
        }
        $maps= UrlUri::mapsActualUrl($controller['url'], $uriapp) && UrlUri::mapsActualMethod($httpMethod, $method);
        if($maps){
            $mapController= array(
                'url' => $controller['url'],
                'httpMethod' => $httpMethod,
                'location' => isset($controller['location']) ? $controller['location'] : NULL,
                'namespace' => isset($controller['namespace']) ? $controller['namespace'] : NULL,
                'class' => isset($controller['class']) ? $controller['class'] : $parentController['class'],
                'method' => isset($controller['method']) ? $controller['method'] : NULL,
                'properties' => isset($controller['properties']) ? $controller['properties'] : array(),
                'middlewares' => isset($controller['middlewares']) ? $controller['middlewares'] : []
            );
            if($parentController != NULL){
                if(! isset($controller['class'])){
                    $mapController['location']= isset($parentController['location']) ? $parentController['location'] : NULL;
                    $mapController['namespace']= isset($parentController['namespace']) ? $parentController['namespace'] : NULL;
                }
                if(isset($parentController['properties'])){
                    $mapController['properties']= array_merge($parentController['properties'], $mapController['properties']);
                }
                if(isset($parentController['middlewares'])){
                    $mapController['middlewares'] = array_merge($parentController['middlewares'], $mapController['middlewares']);
                }
            }
            
            return $mapController;
        }else{
            return NULL;
        }
    }
60090
private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        foreach ($parentClass->associationMappings as $field => $mapping) {
            if ($parentClass->isMappedSuperclass) {
                if ($mapping['type'] & ClassMetadata::TO_MANY && !$mapping['isOwningSide']) {
                    throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->name, $field);
                }
                $mapping['sourceEntity'] = $subClass->name;
            }

            //$subclassMapping = $mapping;
            if ( ! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
                $mapping['inherited'] = $parentClass->name;
            }
            if ( ! isset($mapping['declared'])) {
                $mapping['declared'] = $parentClass->name;
            }
            $subClass->addInheritedAssociationMapping($mapping);
        }
    }
553301
public function show(string $project, array $params = [])
    {
        $path = $this->buildProjectsPath($project);

        return $this->get($path, $params);
    }
498604
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents = [])
    {
        /** @var $class ClassMetadata */
        /** @var $parent ClassMetadata */
        if ($parent) {
            $this->addInheritedIndexes($class, $parent);
            $this->addInheritedAttributes($class, $parent);

            $class->setInheritanceType($parent->inheritanceType);
            $class->setDiscriminatorAttribute($parent->discriminatorAttribute);
            $class->setDiscriminatorMap($parent->discriminatorMap);
            $class->setDiscriminatorDefaultValue($parent->discriminatorDefaultValue);
            $class->setVersioned($parent->isVersioned);
            $class->setVersionAttribute($parent->versionAttribute);
            $class->setLifecycleCallbacks($parent->lifecycleCallbacks);
            $class->setAlsoLoadMethods($parent->alsoLoadMethods);
            $class->setChangeTrackingPolicy($parent->changeTrackingPolicy);

            if ($parent->isMappedSuperclass) {
                $class->setCustomRepositoryClass($parent->customRepositoryClassName);
            }
        }

        // Invoke driver
        try {
            $this->driver->loadMetadataForClass($class->getName(), $class);
        } catch (\ReflectionException $e) {
            throw MappingException::reflectionFailure($class->getName(), $e);
        }

        if (!$class->getIndex() && !$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
            throw MappingException::hashKeyRequired($class->name);
        }

        $class->setParentClassNames($nonSuperclassParents);

        if ($parent) {
            if ($parent->isInheritanceTypeSingleTable()) {
                $class->setTable($parent->getTableName());
                $class->setRequireIndexes($parent->requireIndexes);
            } elseif ($class->requireIndexes === null) {
                $class->setRequireIndexes($parent->requireIndexes);
            }
        }

        if ($this->evm->hasListeners(Event::loadClassMetadata)) {
            $eventArgs = new LoadClassMetadataEventArgs($class, $this->dm);
            $this->evm->dispatchEvent(Event::loadClassMetadata, $eventArgs);
        }
    }
404460
public function createInherited(ClassMetadata $parentClass, PropertyMetadata $parentMapping)
    {
        $mapping = clone $parentMapping;

        if ($mapping->isInherited === null && !$parentClass->isMappedSuperclass) {
            $mapping->isInherited = true;
        }

        return $mapping;
    }
1161789
private function convertClassAnnotationsToMappedSuperClassMetadata(
        array $classAnnotations,
        ReflectionClass $reflectionClass,
        Mapping\ClassMetadata $parent
    ) {
        /** @var Annotation\MappedSuperclass $mappedSuperclassAnnot */
        $mappedSuperclassAnnot = $classAnnotations[Annotation\MappedSuperclass::class];
        $classMetadata         = new Mapping\MappedSuperClassMetadata($reflectionClass->getName(), $parent);

        if ($mappedSuperclassAnnot->repositoryClass !== null) {
            $classMetadata->setCustomRepositoryClassName($mappedSuperclassAnnot->repositoryClass);
        }

        return $classMetadata;
    }