Exemplo n.º 1
0
    /**
     * Processes path.
     *
     * @param string  $path     Path.
     * @param integer $revision Revision.
     * @param string  $action   Action.
     * @param boolean $is_usage This is usage.
     *
     * @return integer
     */
    protected function processPath($path, $revision, $action, $is_usage = true)
    {
        $path_hash = $this->repositoryFiller->getPathChecksum($path);
        $sql = 'SELECT Id, ProjectPath, RefName, RevisionAdded, RevisionDeleted, RevisionLastSeen
				FROM Paths
				WHERE PathHash = :path_hash';
        $path_data = $this->_databaseCache->getFromCache('Paths', $path_hash, $sql, array('path_hash' => $path_hash));
        if ($path_data !== false) {
            if ($action) {
                $fields_hash = $this->repositoryFiller->getPathTouchFields($action, $revision, $path_data);
                if ($fields_hash) {
                    $touched_paths = $this->repositoryFiller->touchPath($path, $revision, $fields_hash);
                    foreach ($touched_paths as $touched_path_hash => $touched_path_fields_hash) {
                        if ($this->_databaseCache->getFromCache('Paths', $touched_path_hash) !== false) {
                            $this->_databaseCache->setIntoCache('Paths', $touched_path_hash, $touched_path_fields_hash);
                        }
                    }
                }
            }
            if ($path_data['ProjectPath'] && $path_data['RefName']) {
                $project_id = $this->processProject($path_data['ProjectPath'], $is_usage);
                // There is no project for missing copy source paths.
                if ($project_id) {
                    $this->processRef($project_id, $path_data['RefName'], $is_usage);
                }
            }
            $this->recordStatistic(self::STATISTIC_PATH_FOUND);
            return $path_data['Id'];
        }
        $ref = $this->_repositoryConnector->getRefByPath($path);
        if ($ref !== false) {
            $project_path = substr($path, 0, strpos($path, $ref));
            if ($this->_pathCollisionDetector->isCollision($project_path)) {
                $project_path = $ref = '';
                $this->recordStatistic(self::STATISTIC_PROJECT_COLLISION_FOUND);
            }
        } else {
            $project_path = '';
        }
        $path_id = $this->repositoryFiller->addPath($path, (string) $ref, $project_path, $revision);
        $this->_databaseCache->setIntoCache('Paths', $path_hash, array('Id' => $path_id, 'ProjectPath' => $project_path, 'RefName' => (string) $ref, 'RevisionAdded' => $revision, 'RevisionDeleted' => null, 'RevisionLastSeen' => $revision));
        if ($project_path && $ref) {
            $project_id = $this->processProject($project_path, $is_usage);
            // There is no project for missing copy source paths.
            if ($project_id) {
                $this->processRef($project_id, $ref, $is_usage);
            }
        }
        $this->recordStatistic(self::STATISTIC_PATH_ADDED);
        return $path_id;
    }
 public function testNoCollisionWithRootPathIsKnownPath()
 {
     $this->pathCollisionDetector->addPaths(array('/'));
     $this->assertFalse($this->pathCollisionDetector->isCollision('/'));
 }