Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / editor / PhabricatorRepositoryEditor.php
blobe2a4164e19ab88665e82b1aa0856f3c8aac8668c
1 <?php
3 final class PhabricatorRepositoryEditor
4 extends PhabricatorApplicationTransactionEditor {
6 public function getEditorApplicationClass() {
7 return 'PhabricatorDiffusionApplication';
10 public function getEditorObjectsDescription() {
11 return pht('Repositories');
14 public function getTransactionTypes() {
15 $types = parent::getTransactionTypes();
17 $types[] = PhabricatorTransactions::TYPE_EDGE;
18 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
19 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
21 return $types;
24 protected function didCatchDuplicateKeyException(
25 PhabricatorLiskDAO $object,
26 array $xactions,
27 Exception $ex) {
29 $errors = array();
31 $errors[] = new PhabricatorApplicationTransactionValidationError(
32 null,
33 pht('Invalid'),
34 pht(
35 'The chosen callsign or repository short name is already in '.
36 'use by another repository.'),
37 null);
39 throw new PhabricatorApplicationTransactionValidationException($errors);
42 protected function supportsSearch() {
43 return true;
46 protected function applyFinalEffects(
47 PhabricatorLiskDAO $object,
48 array $xactions) {
50 // If the repository does not have a local path yet, assign it one based
51 // on its ID. We can't do this earlier because we won't have an ID yet.
52 $local_path = $object->getLocalPath();
53 if ($local_path === null || !strlen($local_path)) {
54 $local_key = 'repository.default-local-path';
56 $local_root = PhabricatorEnv::getEnvConfig($local_key);
57 $local_root = rtrim($local_root, '/');
59 $id = $object->getID();
60 $local_path = "{$local_root}/{$id}/";
62 $object->setLocalPath($local_path);
63 $object->save();
66 if ($this->getIsNewObject()) {
67 // The default state of repositories is to be hosted, if they are
68 // enabled without configuring any "Observe" URIs.
69 $object->setHosted(true);
70 $object->save();
72 // Create this repository's builtin URIs.
73 $builtin_uris = $object->newBuiltinURIs();
74 foreach ($builtin_uris as $uri) {
75 $uri->save();
78 id(new DiffusionRepositoryClusterEngine())
79 ->setViewer($this->getActor())
80 ->setRepository($object)
81 ->synchronizeWorkingCopyAfterCreation();
84 $object->writeStatusMessage(
85 PhabricatorRepositoryStatusMessage::TYPE_NEEDS_UPDATE,
86 null);
88 return $xactions;