protected function newEditableObject() { $uri = PhabricatorRepositoryURI::initializeNewURI(); $repository = $this->getRepository(); if ($repository) { $uri->setRepositoryPHID($repository->getPHID()); $uri->attachRepository($repository); } return $uri; }
public function newBuiltinURIs() { $has_callsign = $this->getCallsign() !== null; $has_shortname = $this->getRepositorySlug() !== null; // TODO: For now, never enable these because they don't work yet. $has_shortname = false; $identifier_map = array(PhabricatorRepositoryURI::BUILTIN_IDENTIFIER_CALLSIGN => $has_callsign, PhabricatorRepositoryURI::BUILTIN_IDENTIFIER_SHORTNAME => $has_shortname, PhabricatorRepositoryURI::BUILTIN_IDENTIFIER_ID => true); // If the view policy of the repository is public, support anonymous HTTP // even if authenticated HTTP is not supported. if ($this->getViewPolicy() === PhabricatorPolicies::POLICY_PUBLIC) { $allow_http = true; } else { $allow_http = PhabricatorEnv::getEnvConfig('diffusion.allow-http-auth'); } $base_uri = PhabricatorEnv::getURI('/'); $base_uri = new PhutilURI($base_uri); $has_https = $base_uri->getProtocol() == 'https'; $has_https = $has_https && $allow_http; $has_http = !PhabricatorEnv::getEnvConfig('security.require-https'); $has_http = $has_http && $allow_http; // HTTP is not supported for Subversion. if ($this->isSVN()) { $has_http = false; $has_https = false; } $has_ssh = (bool) strlen(PhabricatorEnv::getEnvConfig('phd.user')); $protocol_map = array(PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH => $has_ssh, PhabricatorRepositoryURI::BUILTIN_PROTOCOL_HTTPS => $has_https, PhabricatorRepositoryURI::BUILTIN_PROTOCOL_HTTP => $has_http); $uris = array(); foreach ($protocol_map as $protocol => $proto_supported) { foreach ($identifier_map as $identifier => $id_supported) { // This is just a dummy value because it can't be empty; we'll force // it to a proper value when using it in the UI. $builtin_uri = "{$protocol}://{$identifier}"; $uris[] = PhabricatorRepositoryURI::initializeNewURI()->setRepositoryPHID($this->getPHID())->attachRepository($this)->setBuiltinProtocol($protocol)->setBuiltinIdentifier($identifier)->setURI($builtin_uri)->setIsDisabled((int) (!$proto_supported || !$id_supported)); } } return $uris; }
<?php $table = new PhabricatorRepository(); $conn_w = $table->establishConnection('w'); $mirrors = queryfx_all($conn_w, 'SELECT * FROM %T', 'repository_mirror'); foreach ($mirrors as $mirror) { $repository_phid = $mirror['repositoryPHID']; $uri = $mirror['remoteURI']; $already_exists = id(new PhabricatorRepositoryURI())->loadOneWhere('repositoryPHID = %s AND uri = %s', $repository_phid, $uri); if ($already_exists) { // Decline to migrate stuff that looks like it was already migrated. continue; } $new_uri = PhabricatorRepositoryURI::initializeNewURI()->setIOType(PhabricatorRepositoryURI::IO_MIRROR)->setRepositoryPHID($repository_phid)->setURI($uri)->setCredentialPHID($mirror['credentialPHID'])->setDateCreated($mirror['dateCreated'])->setDateModified($mirror['dateModified'])->save(); echo tsprintf("%s\n", pht('Migrated mirror "%s".', $uri)); }
case 'off': default: $disable_ssh = true; break; } $uris = $repository->newBuiltinURIs(); foreach ($uris as $uri) { $builtin_protocol = $uri->getBuiltinProtocol(); if ($builtin_protocol == PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH) { $uri->setIsDisabled((int) $disable_ssh); $uri->setIoType($ssh_io); } else { $uri->setIsDisabled((int) $disable_http); $uri->setIoType($http_io); } } if (!$repository->isHosted()) { $remote_uri = $repository->getDetail('remote-uri'); if (strlen($remote_uri)) { $uris[] = PhabricatorRepositoryURI::initializeNewURI()->setRepositoryPHID($repository->getPHID())->attachRepository($repository)->setURI($remote_uri)->setCredentialPHID($repository->getCredentialPHID())->setIOType(PhabricatorRepositoryURI::IO_OBSERVE); } } foreach ($uris as $uri) { $already_exists = id(new PhabricatorRepositoryURI())->loadOneWhere('repositoryPHID = %s AND uri = %s LIMIT 1', $repository->getPHID(), $uri->getURI()); if ($already_exists) { continue; } $uri->save(); echo tsprintf("%s\n", pht('Migrated URI "%s" for repository "%s".', $uri->getURI(), $repository->getDisplayName())); } }