diff --git a/resources/sql/autopatches/20160418.repouri.1.sql b/resources/sql/autopatches/20160418.repouri.1.sql new file mode 100644 index 0000000000..89f48b4291 --- /dev/null +++ b/resources/sql/autopatches/20160418.repouri.1.sql @@ -0,0 +1,14 @@ +CREATE TABLE {$NAMESPACE}_repository.repository_uri ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARBINARY(64) NOT NULL, + repositoryPHID VARBINARY(64) NOT NULL, + uri VARCHAR(255) NOT NULL COLLATE {$COLLATE_TEXT}, + builtinProtocol VARCHAR(32) COLLATE {$COLLATE_TEXT}, + builtinIdentifier VARCHAR(32) COLLATE {$COLLATE_TEXT}, + ioType VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}, + displayType VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}, + isDisabled BOOL NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + UNIQUE KEY `key_builtin` (repositoryPHID, builtinProtocol, builtinIdentifier) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/applications/repository/storage/PhabricatorRepositoryURI.php b/src/applications/repository/storage/PhabricatorRepositoryURI.php index c91861918f..9a93e261e4 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryURI.php +++ b/src/applications/repository/storage/PhabricatorRepositoryURI.php @@ -1,300 +1,300 @@ true, self::CONFIG_COLUMN_SCHEMA => array( - 'uri' => 'text', + 'uri' => 'text255', 'builtinProtocol' => 'text32?', 'builtinIdentifier' => 'text32?', 'ioType' => 'text32', 'displayType' => 'text32', 'isDisabled' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( 'key_builtin' => array( 'columns' => array( 'repositoryPHID', 'builtinProtocol', 'builtinIdentifier', ), 'unique' => true, ), ), ) + parent::getConfiguration(); } public static function initializeNewURI(PhabricatorRepository $repository) { return id(new self()) ->attachRepository($repository) ->setRepositoryPHID($repository->getPHID()) ->setIoType(self::IO_DEFAULT) ->setDisplayType(self::DISPLAY_DEFAULT) ->setIsDisabled(0); } public function attachRepository(PhabricatorRepository $repository) { $this->repository = $repository; return $this; } public function getRepository() { return $this->assertAttached($this->repository); } public function getRepositoryURIBuiltinKey() { if (!$this->getBuiltinProtocol()) { return null; } $parts = array( $this->getBuiltinProtocol(), $this->getBuiltinIdentifier(), ); return implode('.', $parts); } public function isBuiltin() { return (bool)$this->getBuiltinProtocol(); } public function getEffectiveDisplayType() { $display = $this->getDisplayType(); if ($display != self::IO_DEFAULT) { return $display; } switch ($this->getEffectiveIOType()) { case self::IO_MIRROR: case self::IO_OBSERVE: return self::DISPLAY_NEVER; case self::IO_NONE: if ($this->isBuiltin()) { return self::DISPLAY_NEVER; } else { return self::DISPLAY_ALWAYS; } case self::IO_READ: case self::IO_READWRITE: // By default, only show the "best" version of the builtin URI, not the // other redundant versions. if ($this->isBuiltin()) { $repository = $this->getRepository(); $other_uris = $repository->getURIs(); $identifier_value = array( self::BUILTIN_IDENTIFIER_CALLSIGN => 3, self::BUILTIN_IDENTIFIER_SHORTNAME => 2, self::BUILTIN_IDENTIFIER_ID => 1, ); $have_identifiers = array(); foreach ($other_uris as $other_uri) { if ($other_uri->getIsDisabled()) { continue; } $identifier = $other_uri->getBuiltinIdentifier(); if (!$identifier) { continue; } $have_identifiers[$identifier] = $identifier_value[$identifier]; } $best_identifier = max($have_identifiers); $this_identifier = $identifier_value[$this->getBuiltinIdentifier()]; if ($this_identifier < $best_identifier) { return self::DISPLAY_NEVER; } } return self::DISPLAY_ALWAYS; } } public function getEffectiveIOType() { $io = $this->getIoType(); if ($io != self::IO_DEFAULT) { return $io; } if ($this->isBuiltin()) { $repository = $this->getRepository(); $other_uris = $repository->getURIs(); $any_observe = false; foreach ($other_uris as $other_uri) { if ($other_uri->getIoType() == self::IO_OBSERVE) { $any_observe = true; break; } } if ($any_observe) { return self::IO_READ; } else { return self::IO_READWRITE; } } return self::IO_IGNORE; } public function getDisplayURI() { $uri = new PhutilURI($this->getURI()); $protocol = $this->getForcedProtocol(); if ($protocol) { $uri->setProtocol($protocol); } $user = $this->getForcedUser(); if ($user) { $uri->setUser($user); } $host = $this->getForcedHost(); if ($host) { $uri->setDomain($host); } $port = $this->getForcedPort(); if ($port) { $uri->setPort($port); } $path = $this->getForcedPath(); if ($path) { $uri->setPath($path); } return $uri; } private function getForcedProtocol() { switch ($this->getBuiltinProtocol()) { case self::BUILTIN_PROTOCOL_SSH: return 'ssh'; case self::BUILTIN_PROTOCOL_HTTP: return 'http'; case self::BUILTIN_PROTOCOL_HTTPS: return 'https'; default: return null; } } private function getForcedUser() { switch ($this->getBuiltinProtocol()) { case self::BUILTIN_PROTOCOL_SSH: return PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); default: return null; } } private function getForcedHost() { $phabricator_uri = PhabricatorEnv::getURI('/'); $phabricator_uri = new PhutilURI($phabricator_uri); $phabricator_host = $phabricator_uri->getDomain(); switch ($this->getBuiltinProtocol()) { case self::BUILTIN_PROTOCOL_SSH: $ssh_host = PhabricatorEnv::getEnvConfig('diffusion.ssh-host'); if ($ssh_host !== null) { return $ssh_host; } return $phabricator_host; case self::BUILTIN_PROTOCOL_HTTP: case self::BUILTIN_PROTOCOL_HTTPS: return $phabricator_host; default: return null; } } private function getForcedPort() { switch ($this->getBuiltinProtocol()) { case self::BUILTIN_PROTOCOL_SSH: return PhabricatorEnv::getEnvConfig('diffusion.ssh-port'); case self::BUILTIN_PROTOCOL_HTTP: case self::BUILTIN_PROTOCOL_HTTPS: default: return null; } } private function getForcedPath() { if (!$this->isBuiltin()) { return null; } $repository = $this->getRepository(); $id = $repository->getID(); $callsign = $repository->getCallsign(); $short_name = $repository->getRepositorySlug(); $clone_name = $repository->getCloneName(); if ($repository->isGit()) { $suffix = '.git'; } else if ($repository->isHg()) { $suffix = '/'; } else { $suffix = ''; } switch ($this->getBuiltinIdentifier()) { case self::BUILTIN_IDENTIFIER_ID: return "/diffusion/{$id}/{$clone_name}{$suffix}"; case self::BUILTIN_IDENTIFIER_SHORTNAME: return "/source/{$short_name}{$suffix}"; case self::BUILTIN_IDENTIFIER_CALLSIGN: return "/diffusion/{$callsign}/{$clone_name}{$suffix}"; default: return null; } } } diff --git a/src/infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php b/src/infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php index 2624427dc8..3a10f77bc7 100644 --- a/src/infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php +++ b/src/infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php @@ -1,43 +1,43 @@ name = $name; execx( - 'php %s upgrade --force --no-adjust --namespace %s', + 'php %s upgrade --force --namespace %s', $this->getStorageBinPath(), $this->name); PhabricatorLiskDAO::pushStorageNamespace($name); // Destructor is not called with fatal error. register_shutdown_function(array($this, 'destroy')); } public function destroy() { PhabricatorLiskDAO::popStorageNamespace(); // NOTE: We need to close all connections before destroying the databases. // If we do not, the "DROP DATABASE ..." statements may hang, waiting for // our connections to close. PhabricatorLiskDAO::closeAllConnections(); execx( 'php %s destroy --force --namespace %s', $this->getStorageBinPath(), $this->name); } private function getStorageBinPath() { $root = dirname(phutil_get_library_root('phabricator')); return $root.'/scripts/sql/manage_storage.php'; } }