Skip to content

Commit

Permalink
refactor: deprecate NotificationQueries class
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed May 29, 2024
1 parent 86dfdae commit eb2dd40
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@

/**
* Notification Queries class
*
* @deprecated [Next]
*/
class NotificationQueries
{
/**
* Class constructor
*/
public function __construct()
{
notification_deprecated_class( __CLASS__, '[Next]' );
}

/**
* Gets Notification posts.
*
Expand Down
10 changes: 5 additions & 5 deletions compat/src-deprecated/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
use BracketSpace\Notification\Core\Sync;
use BracketSpace\Notification\Core\Templates;
use BracketSpace\Notification\Core\Whitelabel;
use BracketSpace\Notification\Database\NotificationDatabaseService;
use BracketSpace\Notification\Interfaces;
use BracketSpace\Notification\Register;
use BracketSpace\Notification\Store;
use BracketSpace\Notification\Dependencies\Micropackage\DocHooks\Helper as DocHooksHelper;
use BracketSpace\Notification\Database\Queries\NotificationQueries;

/**
* Helper function.
Expand Down Expand Up @@ -118,9 +118,9 @@ function notification_filesystem( $deprecated ) {
* @return array
*/
function notification_get_posts( $trigger_slug = null, $all = false ) {
_deprecated_function( __FUNCTION__, '8.0.0', 'BracketSpace\\Notification\\Database\\Queries\\NotificationQueries::all()' );
_deprecated_function( __FUNCTION__, '8.0.0', 'BracketSpace\\Notification\\Database\\NotificationDatabaseService::getAll()' );

return NotificationQueries::all( $all );
return NotificationDatabaseService::getAll();
}

/**
Expand All @@ -132,9 +132,9 @@ function notification_get_posts( $trigger_slug = null, $all = false ) {
* @return mixed null or Notification object
*/
function notification_get_post_by_hash( $hash ) {
_deprecated_function( __FUNCTION__, '8.0.0', 'BracketSpace\\Notification\\Database\\Queries\\NotificationQueries::with_hash()' );
_deprecated_function( __FUNCTION__, '8.0.0', 'BracketSpace\\Notification\\Database\\NotificationDatabaseService::get()' );

return NotificationQueries::withHash( $hash );
return NotificationDatabaseService::get( $hash );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ parameters:
count: 2
path: compat/src-deprecated/Adapter/WordPress.php

-
message: "#^Parameter \\#1 \\$args of function get_posts expects array\\{numberposts\\?\\: int, category\\?\\: int\\|string, include\\?\\: array\\<int\\>, exclude\\?\\: array\\<int\\>, suppress_filters\\?\\: bool, attachment_id\\?\\: int, author\\?\\: int\\|string, author_name\\?\\: string, \\.\\.\\.\\}\\|null, array\\{posts_per_page\\: \\-1, post_type\\: 'notification', post_status\\?\\: array\\{'publish', 'draft'\\}, suppress_filters\\?\\: 0\\} given\\.$#"
count: 1
path: compat/src-deprecated/Database/Queries/NotificationQueries.php

-
message: "#^Method BracketSpace\\\\Notification\\\\Utils\\\\Interfaces\\\\Cacheable\\:\\:add\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -1140,11 +1145,6 @@ parameters:
count: 1
path: src/Core/Upgrade.php

-
message: "#^Parameter \\#1 \\$args of function get_posts expects array\\{numberposts\\?\\: int, category\\?\\: int\\|string, include\\?\\: array\\<int\\>, exclude\\?\\: array\\<int\\>, suppress_filters\\?\\: bool, attachment_id\\?\\: int, author\\?\\: int\\|string, author_name\\?\\: string, \\.\\.\\.\\}\\|null, array\\{posts_per_page\\: \\-1, post_type\\: 'notification', post_status\\?\\: array\\{'publish', 'draft'\\}, suppress_filters\\?\\: 0\\} given\\.$#"
count: 1
path: src/Database/Queries/NotificationQueries.php

-
message: "#^Method BracketSpace\\\\Notification\\\\Database\\\\Queries\\\\UserQueries\\:\\:all\\(\\) should return array\\<int, array\\{ID\\: string, user_email\\: string, display_name\\: string\\}\\> but returns mixed\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ Removed deprecated hooks:
* [Fixed] Email carrier header "From" prioritized over header in settings.
* [Fixed] User password reset link requires encoded username.
* [Removed] DOING_NOTIFICATION_SAVE constant.
* [Removed] NotificationQueries class in favor of NotificationDatabaseService.

== Upgrade Notice ==

Expand Down
12 changes: 1 addition & 11 deletions src/Admin/ImportExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use BracketSpace\Notification\Core\Notification;
use BracketSpace\Notification\Database\NotificationDatabaseService as Db;
use BracketSpace\Notification\Utils\Settings\Fields as SettingFields;
use BracketSpace\Notification\Database\Queries\NotificationQueries;

/**
* Import/Export class
Expand Down Expand Up @@ -218,10 +217,7 @@ public function processNotificationsImportRequest($data)
foreach ($data as $notificationData) {
$notification = Notification::from('json', (string)wp_json_encode($notificationData));

/**
* @var \BracketSpace\Notification\Defaults\Adapter\WordPress|null
*/
$existingNotification = NotificationQueries::withHash($notification->getHash());
$existingNotification = Db::get($notification->getHash());

if ($existingNotification === null) {
Db::upsert($notification);
Expand All @@ -230,12 +226,6 @@ public function processNotificationsImportRequest($data)
if ($existingNotification->getVersion() >= $notification->getVersion()) {
$skipped++;
} else {
$post = $existingNotification->getPost();

if (is_null($post)) {
continue;
}

Db::upsert($notification);
$updated++;
}
Expand Down
9 changes: 2 additions & 7 deletions src/Admin/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use BracketSpace\Notification\Database\NotificationDatabaseService;
use BracketSpace\Notification\Utils\Settings\CoreFields;
use BracketSpace\Notification\Utils\Settings\Fields as SpecificFields;
use BracketSpace\Notification\Database\Queries\NotificationQueries;
use BracketSpace\Notification\Dependencies\Micropackage\Ajax\Response;

/**
Expand Down Expand Up @@ -120,7 +119,7 @@ public function ajaxSync()
*/
public function loadNotificationToJson($hash)
{
$notification = NotificationQueries::withHash($hash);
$notification = NotificationDatabaseService::get($hash);

if ($notification === null) {
return;
Expand All @@ -147,11 +146,7 @@ public function loadNotificationToWordpress($hash)
if ($notification->getHash() === $hash) {
NotificationDatabaseService::upsert($notification);

/**
* Get post edit link from freshly inserted notification
* @todo 3mp4ad
*/
return get_edit_post_link(0, 'admin');
return get_edit_post_link(NotificationDatabaseService::getLastUpsertedPostId(), 'admin');
}
} catch (\Throwable $e) {
// Do nothing.
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Settings/Fields/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace BracketSpace\Notification\Utils\Settings\Fields;

use BracketSpace\Notification\Core\Templates;
use BracketSpace\Notification\Database\Queries\NotificationQueries;
use BracketSpace\Notification\Database\NotificationDatabaseService;

/**
* Export class
Expand All @@ -35,7 +35,7 @@ public function input($field)
Templates::render(
'export/notifications',
[
'notifications' => NotificationQueries::all(true),
'notifications' => NotificationDatabaseService::getAll(),
'download_link' => $downloadLink,
]
);
Expand Down
16 changes: 6 additions & 10 deletions src/Utils/Settings/Fields/SyncTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

namespace BracketSpace\Notification\Utils\Settings\Fields;

use BracketSpace\Notification\Admin\PostType;
use BracketSpace\Notification\Core\Notification;
use BracketSpace\Notification\Core\Sync as CoreSync;
use BracketSpace\Notification\Core\Templates;
use BracketSpace\Notification\Database\Queries\NotificationQueries;
use BracketSpace\Notification\Database\NotificationDatabaseService;

/**
* SyncTable class
Expand All @@ -30,26 +29,23 @@ class SyncTable
public function input($field)
{
// Get all Notifications.
$wpJsonNotifiactions = PostType::getAllNotifications();
$wpNotifiactions = NotificationDatabaseService::getAll();
$jsonNotifications = CoreSync::getAllJson();
$collection = [];

// Load the WP Notifications first.
foreach ($wpJsonNotifiactions as $notification) {
/**
* @var \BracketSpace\Notification\Defaults\Adapter\WordPress|null
*/
$notificationAdapter = NotificationQueries::withHash($notification->getHash());
foreach ($wpNotifiactions as $notification) {
$post = NotificationDatabaseService::notificationToPost($notification);

if ($notificationAdapter === null) {
if ($post === null) {
continue;
}

$collection[$notification->getHash()] = [
'source' => 'WordPress',
'has_json' => false,
'up_to_date' => false,
'post_id' => $notificationAdapter->getId(),
'post_id' => $post->ID,
'notification' => $notification,
];
}
Expand Down

0 comments on commit eb2dd40

Please sign in to comment.