@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Conduit: Fix PHP 8.1 "preg_replace(null)" exceptions in phriction.{edit|info}

Summary:
Passing null to `preg_match()` is deprecated since PHP 8.1.

```
ERROR 8192: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated at [/var/www/html/phorge/phorge/src/infrastructure/util/PhabricatorSlug.php:17]
```

Closes T16424

Test Plan:
* PHP 8.1+
* Go to http://phorge.localhost/conduit/method/phriction.edit/ and press the "Call Method" button
* Go to http://phorge.localhost/conduit/method/phriction.info/ and press the "Call Method" button

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16424

Differential Revision: https://we.phorge.it/D26635

+31 -19
+23 -14
src/applications/phriction/conduit/PhrictionEditConduitAPIMethod.php
··· 23 23 return 'nonempty dict'; 24 24 } 25 25 26 + protected function defineErrorTypes() { 27 + return array( 28 + 'ERR-BAD-DOCUMENT' => pht('No such document exists.'), 29 + ); 30 + } 31 + 26 32 protected function execute(ConduitAPIRequest $request) { 27 33 $slug = $request->getValue('slug'); 34 + $document = null; 28 35 29 - $doc = id(new PhrictionDocumentQuery()) 30 - ->setViewer($request->getUser()) 31 - ->withSlugs(array(PhabricatorSlug::normalize($slug))) 32 - ->needContent(true) 33 - ->requireCapabilities( 34 - array( 35 - PhabricatorPolicyCapability::CAN_VIEW, 36 - PhabricatorPolicyCapability::CAN_EDIT, 37 - )) 38 - ->executeOne(); 39 - if (!$doc) { 40 - throw new Exception(pht('No such document.')); 36 + if ($slug !== null) { 37 + $document = id(new PhrictionDocumentQuery()) 38 + ->setViewer($request->getUser()) 39 + ->withSlugs(array(PhabricatorSlug::normalize($slug))) 40 + ->needContent(true) 41 + ->requireCapabilities( 42 + array( 43 + PhabricatorPolicyCapability::CAN_VIEW, 44 + PhabricatorPolicyCapability::CAN_EDIT, 45 + )) 46 + ->executeOne(); 47 + } 48 + if (!$document) { 49 + throw new ConduitException('ERR-BAD-DOCUMENT'); 41 50 } 42 51 43 52 $xactions = array(); ··· 62 71 ->setDescription((string)$request->getValue('description')); 63 72 64 73 try { 65 - $editor->applyTransactions($doc, $xactions); 74 + $editor->applyTransactions($document, $xactions); 66 75 } catch (PhabricatorApplicationTransactionValidationException $ex) { 67 76 // TODO - some magical hotness via T5873 68 77 throw $ex; 69 78 } 70 79 71 - return $this->buildDocumentInfoDictionary($doc); 80 + return $this->buildDocumentInfoDictionary($document); 72 81 } 73 82 74 83 }
+8 -5
src/applications/phriction/conduit/PhrictionInfoConduitAPIMethod.php
··· 38 38 39 39 protected function execute(ConduitAPIRequest $request) { 40 40 $slug = $request->getValue('slug'); 41 + $document = null; 41 42 42 - $document = id(new PhrictionDocumentQuery()) 43 - ->setViewer($request->getUser()) 44 - ->withSlugs(array(PhabricatorSlug::normalize($slug))) 45 - ->needContent(true) 46 - ->executeOne(); 43 + if ($slug !== null) { 44 + $document = id(new PhrictionDocumentQuery()) 45 + ->setViewer($request->getUser()) 46 + ->withSlugs(array(PhabricatorSlug::normalize($slug))) 47 + ->needContent(true) 48 + ->executeOne(); 49 + } 47 50 if (!$document) { 48 51 throw new ConduitException('ERR-BAD-DOCUMENT'); 49 52 }