Skip to content

Commit 8e3f3dd

Browse files
committed
support xf 2.3.x
1 parent d66820e commit 8e3f3dd

19 files changed

+80
-66
lines changed

Api/Controller/App.php renamed to Api/Controller/AppController.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use LogicException;
1212
use function strlen;
1313
use XF\Http\Request;
14-
use XF\Finder\Thread;
1514
use function in_array;
1615
use XF\Mvc\Dispatcher;
1716
use XF\Mvc\Reply\Error;
@@ -46,7 +45,7 @@
4645
use Truonglv\Api\Payment\PurchaseExpiredException;
4746
use Truonglv\Api\XF\ConnectedAccount\Storage\StorageState;
4847

49-
class App extends AbstractController
48+
class AppController extends AbstractController
5049
{
5150
public function actionGet()
5251
{
@@ -66,8 +65,7 @@ public function actionGetNewsFeeds()
6665
/** @var \XF\Entity\Search|null $search */
6766
$search = null;
6867
if ($searchId > 0) {
69-
/** @var \XF\Entity\Search|null $existingSearch */
70-
$existingSearch = $this->em()->find('XF:Search', $searchId);
68+
$existingSearch = $this->em()->find(XF\Entity\Search::class, $searchId);
7169
if ($existingSearch !== null
7270
&& $existingSearch->user_id === $visitor->user_id
7371
&& $existingSearch->search_query === $searchQuery
@@ -165,8 +163,7 @@ public function actionPostLogOut()
165163
{
166164
$accessToken = $this->request()->getServer(\Truonglv\Api\App::HEADER_KEY_ACCESS_TOKEN);
167165

168-
/** @var AccessToken|null $token */
169-
$token = $this->em()->find('Truonglv\Api:AccessToken', $accessToken);
166+
$token = $this->em()->find(AccessToken::class, $accessToken);
170167
if ($token !== null) {
171168
$token->delete();
172169
}
@@ -506,7 +503,7 @@ public function actionPostIAPVerify()
506503
'purchase' => $this->filter('purchase', 'str'),
507504
];
508505

509-
$jsonPayload['purchase'] = \GuzzleHttp\json_decode($jsonPayload['purchase'], true);
506+
$jsonPayload['purchase'] = \GuzzleHttp\Utils::jsonDecode($jsonPayload['purchase'], true);
510507
}
511508

512509
/** @var IAPInterface|XF\Payment\AbstractProvider $handler */
@@ -708,7 +705,7 @@ protected function getAuthResultData(\XF\Entity\User $user, bool $withRefreshTok
708705
];
709706

710707
/** @var AccessToken $token */
711-
$token = $this->em()->find('Truonglv\Api:AccessToken', $data['accessToken']);
708+
$token = $this->em()->find(AccessToken::class, $data['accessToken']);
712709
$data['expiresAt'] = $token->expire_date;
713710

714711
if ($withRefreshToken) {
@@ -718,10 +715,6 @@ protected function getAuthResultData(\XF\Entity\User $user, bool $withRefreshTok
718715
return $data;
719716
}
720717

721-
/**
722-
* @param array $job
723-
* @return array|null
724-
*/
725718
protected function runJob(array $job): ?array
726719
{
727720
if (!isset($job['uri'])) {
@@ -933,12 +926,7 @@ protected function getNewsFeedsFilters(): array
933926
return $filters;
934927
}
935928

936-
/**
937-
* @param Thread $finder
938-
* @param array $filters
939-
* @return void
940-
*/
941-
protected function applyNewsFeedsFilter(Thread $finder, array $filters)
929+
protected function applyNewsFeedsFilter(XF\Finder\ThreadFinder $finder, array $filters): void
942930
{
943931
$finder->where('discussion_state', 'visible');
944932
$finder->where('discussion_type', '<>', 'redirect');
@@ -1009,8 +997,7 @@ protected function runNewsFeedSearch(string $searchQuery): ?\XF\Entity\Search
1009997
return null;
1010998
}
1011999

1012-
/** @var \XF\Entity\Search $search */
1013-
$search = $this->em()->create('XF:Search');
1000+
$search = $this->em()->create(XF\Entity\Search::class);
10141001
$search->search_type = 'thread';
10151002
$search->search_query = $searchQuery;
10161003
$search->query_hash = md5(__METHOD__ . $searchQuery . json_encode($filters));

Api/Controller/Bookmark.php renamed to Api/Controller/BookmarkController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use XF\Mvc\Entity\Entity;
77
use XF\Api\Controller\AbstractController;
88

9-
class Bookmark extends AbstractController
9+
class BookmarkController extends AbstractController
1010
{
1111
public function actionGet()
1212
{
@@ -68,12 +68,12 @@ public function actionPost()
6868
$creator = $this->service(XF\Service\Bookmark\CreatorService::class, $content);
6969

7070
$message = $this->filter('message', 'str');
71-
if (utf8_strlen($message) > 0) {
71+
if (\XF\Util\Str::strlen($message) > 0) {
7272
$creator->setMessage($message);
7373
}
7474

7575
$labels = $this->filter('labels', 'str');
76-
if (utf8_strlen($labels) > 0) {
76+
if (\XF\Util\Str::strlen($labels) > 0) {
7777
$creator->setLabels($labels);
7878
}
7979

Api/Controller/Notification.php renamed to Api/Controller/NotificationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use XF\Mvc\Entity\Entity;
1010
use XF\Api\Controller\AbstractController;
1111

12-
class Notification extends AbstractController
12+
class NotificationController extends AbstractController
1313
{
1414
public function actionGet(ParameterBag $params)
1515
{
@@ -82,7 +82,7 @@ protected function getContentApiResultOptions(UserAlert $userAlert): array
8282
protected function assertViewableAlert($alertId): UserAlert
8383
{
8484
/** @var UserAlert $alert */
85-
$alert = $this->assertRecordExists('XF:UserAlert', $alertId);
85+
$alert = $this->assertRecordExists(UserAlert::class, $alertId);
8686
if ($alert->alerted_user_id !== XF::visitor()->user_id) {
8787
throw $this->exception($this->noPermission());
8888
}

Api/Controller/Notifications.php renamed to Api/Controller/NotificationsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use function array_keys;
1313
use XF\Api\Controller\AbstractController;
1414

15-
class Notifications extends AbstractController
15+
class NotificationsController extends AbstractController
1616
{
1717
public function actionGet()
1818
{

Api/Controller/Search.php renamed to Api/Controller/SearchController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
use XF\Entity\Post;
1010
use function strlen;
1111
use XF\Mvc\ParameterBag;
12-
use function utf8_strlen;
1312
use XF\Mvc\Entity\Entity;
14-
use function utf8_strtolower;
1513
use Truonglv\Api\Entity\SearchQuery;
1614
use XF\Api\Controller\AbstractController;
1715
use Truonglv\Api\Repository\SearchQueryRepository;
1816

19-
class Search extends AbstractController
17+
class SearchController extends AbstractController
2018
{
2119
const SEARCH_TYPE_THREAD = 'thread';
2220
const SEARCH_TYPE_POST = 'post';
@@ -86,7 +84,7 @@ public function actionPost()
8684

8785
$query->withGroupedResults();
8886
/** @var SearchQuery $searchQueryLogger */
89-
$searchQueryLogger = $this->em()->create('Truonglv\Api:SearchQuery');
87+
$searchQueryLogger = $this->em()->create(SearchQuery::class);
9088
$searchQueryLogger->user_id = XF::visitor()->user_id;
9189

9290
if ($tag !== null) {
@@ -177,15 +175,15 @@ public function actionUser()
177175
{
178176
$name = $this->filter('name', 'str');
179177

180-
if (utf8_strlen($name) <= 2) {
178+
if (\XF\Util\Str::strlen($name) <= 2) {
181179
return $this->message(XF::phrase('no_results_found'));
182180
}
183181

184182
$queryHash = md5(
185183
$this->app()->config('globalSalt')
186184
. __METHOD__
187185
. self::SEARCH_TYPE_USER
188-
. utf8_strtolower($name)
186+
. \XF\Util\Str::strtolower($name)
189187
);
190188

191189
/** @var \XF\Entity\Search|null $existingSearch */
@@ -219,7 +217,7 @@ public function actionUser()
219217
}
220218

221219
/** @var \XF\Entity\Search $search */
222-
$search = $this->em()->create('XF:Search');
220+
$search = $this->em()->create(XF\Entity\Search::class);
223221

224222
$search->user_id = 0;
225223
$search->result_count = count($searchResults);
@@ -256,7 +254,7 @@ protected function getApiResultOptions(Entity $entity): array
256254
protected function assertSearchViewable($id)
257255
{
258256
/** @var \XF\Entity\Search $search */
259-
$search = $this->assertRecordExists('XF:Search', $id);
257+
$search = $this->assertRecordExists(XF\Entity\Search::class, $id);
260258
if (($search->user_id > 0 && $search->user_id !== XF::visitor()->user_id)
261259
|| (
262260
$search->search_type !== ''

App.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Truonglv\Api;
44

5-
use Truonglv\Api\Service\FirebaseCloudMessagingService;
65
use XF;
76
use function md5;
87
use function strval;

DevHelper/Admin/Controller/Entity.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use XF\Admin\Controller\AbstractController;
1515

1616
/**
17-
* @version 2024081700
17+
* @version 2024092501
1818
* @see \DevHelper\Autogen\Admin\Controller\Entity
1919
*/
2020
abstract class Entity extends AbstractController
@@ -474,7 +474,7 @@ protected function entityGetMetadataForColumns(MvcEntity $entity): array
474474
final protected function entityListData(): array
475475
{
476476
$shortName = $this->getShortName();
477-
$finder = $this->finder($this->getFinderClassName());
477+
$finder = $this->finder($this->getShortName());
478478
$filters = ['pageNavParams' => []];
479479

480480
/** @var mixed $that */
@@ -536,7 +536,7 @@ protected function entitySaveProcess(MvcEntity $entity): FormAction
536536
foreach ($input['hidden_columns'] as $columnName) {
537537
$entity->set(
538538
$columnName,
539-
isset($input['hidden_values'][$columnName]) ? $input['hidden_values'][$columnName] : ''
539+
$input['hidden_values'][$columnName] ?? ''
540540
);
541541
}
542542

@@ -698,7 +698,7 @@ protected function supportsViewing(): bool
698698
protected function supportsXfFilter(): bool
699699
{
700700
/** @var mixed $unknownFinder */
701-
$unknownFinder = $this->finder($this->getFinderClassName());
701+
$unknownFinder = $this->finder($this->getShortName());
702702

703703
return is_callable([$unknownFinder, 'entityDoXfFilter']);
704704
}
@@ -725,7 +725,6 @@ public function getEntityActiveColumn(): ?string
725725
}
726726

727727
abstract protected function getShortName(): string;
728-
abstract protected function getFinderClassName(): string;
729728
abstract protected function getPrefixForClasses(): string;
730729
abstract protected function getPrefixForPhrases(): string;
731730
abstract protected function getPrefixForTemplates(): string;

Repository/AlertQueueRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Truonglv\Api\Repository;
44

5-
use Truonglv\Api\Service\FirebaseCloudMessagingService;
65
use XF;
76
use XF\Timer;
87
use Throwable;
@@ -14,6 +13,7 @@
1413
use XF\Mvc\Entity\AbstractCollection;
1514
use Truonglv\Api\Finder\AlertQueueFinder;
1615
use Truonglv\Api\Service\AbstractPushNotification;
16+
use Truonglv\Api\Service\FirebaseCloudMessagingService;
1717

1818
class AlertQueueRepository extends Repository
1919
{

_files/dev/autogen.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"Admin/Controller/Entity.php": 2024081700,
2+
"Admin/Controller/Entity.php": 2024092501,
33
"DevHelper\\Cli\\Command\\AutoGen": {
4-
"version_id": 2024081701
4+
"version_id": 2024092501
55
},
66
"SetupTrait.php": 2022092802
77
}

_output/extension_hint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

3-
/** @noinspection PhpIllegalPsrClassPathInspection */
43
// ################## THIS IS A GENERATED FILE ##################
54
// DO NOT EDIT DIRECTLY. EDIT THE CLASS EXTENSIONS IN THE CONTROL PANEL.
65

6+
/**
7+
* @noinspection PhpIllegalPsrClassPathInspection
8+
*/
9+
710
namespace Truonglv\Api\XFRM\Api\Controller
811
{
912
class XFCP_ResourceItem extends \XFRM\Api\Controller\ResourceItem {}
@@ -93,4 +96,4 @@ class XFCP_PusherService extends \XF\Service\Alert\PusherService {}
9396
{
9497
class XFCP_NotifierService extends \XF\Service\Conversation\NotifierService {}
9598
class XFCP_PusherService extends \XF\Service\Conversation\PusherService {}
96-
}
99+
}

_output/option_hint.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
// ################## THIS IS A GENERATED FILE ##################
4+
// DO NOT EDIT DIRECTLY. EDIT THE OPTIONS IN THE CONTROL PANEL.
5+
6+
/**
7+
* @noinspection PhpMultipleClassDeclarationsInspection
8+
* @noinspection PhpIllegalPsrClassPathInspection
9+
*/
10+
11+
namespace XF;
12+
13+
/**
14+
* @property non-negative-int|null $tApi_accessTokenTtl Access token TTL
15+
* @property non-negative-int|null $tApi_allowSelfDelete Allow self-delete account via API?
16+
* @property array{apiKeyId: int, key: string}|null $tApi_apiKey Api key
17+
* @property string|null $tApi_appName App name
18+
* @property string|null $tApi_caAppleProviderId Connected accounts: Apple provider
19+
* @property non-negative-int|null $tApi_delayPushNotifications Delay push notifications to users?
20+
* @property non-negative-int|null $tApi_discussionPreviewLength Discussion preview length
21+
* @property string|null $tApi_encryptKey Encrypt data key
22+
* @property string|null $tApi_firebaseConfigPath Firebase config path
23+
* @property non-negative-int|null $tApi_inactiveDeviceLength Remove user subscriptions if inactive in
24+
* @property non-negative-int|null $tApi_logLength Api request log length
25+
* @property array{0: array{reactionId: int, imageUrl: string}, 1: array{reactionId: int, imageUrl: string}, 2: array{reactionId: int, imageUrl: string}, 3: array{reactionId: int, imageUrl: string}, 4: array{reactionId: int, imageUrl: string}, 5: array{reactionId: int, imageUrl: string}}|null $tApi_reactions Reactions
26+
* @property non-negative-int|null $tApi_recordsPerPage Records per page
27+
*/
28+
class Options
29+
{
30+
}

_output/routes/_metadata.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
"hash": "8ba75dbeb6478c246ff2165f5057bad7"
1616
},
1717
"api_tapi-app-notifications_-.json": {
18-
"hash": "94f8a3cd406d582bcb3a38e3983062ba"
18+
"hash": "59023d6d86ce246a88dcc90d16831033"
1919
},
2020
"api_tapi-app-notifications_.json": {
21-
"hash": "a8bef7f7db1e99c945f0e5479e36f044"
21+
"hash": "8b1fbcde2de885ad22969415657e45bb"
2222
},
2323
"api_tapi-apps_.json": {
24-
"hash": "2b7965b480f90fbd96014665d6a2c44b"
24+
"hash": "b8e111f2740280e7940293525cfad32d"
2525
},
2626
"api_tapi-bookmarks_.json": {
27-
"hash": "a1a285b2b2b760296ad3b22b6d8b394d"
27+
"hash": "11f5a0ec9e4a5661b30208848961d9f4"
2828
},
2929
"api_tapi-search_.json": {
30-
"hash": "d43778cf304edaf3d8855e864bd24e64"
30+
"hash": "5e44e8473cfa30ea90a460137302ea50"
3131
}
3232
}

_output/routes/api_tapi-app-notifications_-.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"format": ":+int<alert_id>/",
66
"build_class": "",
77
"build_method": "",
8-
"controller": "Truonglv\\Api:Notification",
8+
"controller": "Truonglv\\Api:NotificationController",
99
"context": "",
1010
"action_prefix": ""
1111
}

_output/routes/api_tapi-app-notifications_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"format": "",
66
"build_class": "",
77
"build_method": "",
8-
"controller": "Truonglv\\Api:Notifications",
8+
"controller": "Truonglv\\Api:NotificationsController",
99
"context": "",
1010
"action_prefix": ""
1111
}

_output/routes/api_tapi-apps_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"format": "",
66
"build_class": "",
77
"build_method": "",
8-
"controller": "Truonglv\\Api:App",
8+
"controller": "Truonglv\\Api:AppController",
99
"context": "",
1010
"action_prefix": ""
1111
}

_output/routes/api_tapi-bookmarks_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"format": "",
66
"build_class": "",
77
"build_method": "",
8-
"controller": "Truonglv\\Api:Bookmark",
8+
"controller": "Truonglv\\Api:BookmarkController",
99
"context": "",
1010
"action_prefix": ""
1111
}

0 commit comments

Comments
 (0)