Skip to content

Commit

Permalink
GH-224 Move ignore entries remover to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 14, 2022
1 parent 3373363 commit 529315d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions modules/settings/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

include($includePath . './utils/queries/createEmailChangeProcessEntry.query.php');
include($includePath . './utils/queries/createUserIgnoreEntry.query.php');
include($includePath . './utils/queries/deleteUserIgnoreEntries.query.php');
include($includePath . './utils/queries/getMovingFleetsCount.query.php');
include($includePath . './utils/queries/getUserWithEmailAddress.query.php');

Expand Down
29 changes: 29 additions & 0 deletions modules/settings/utils/queries/deleteUserIgnoreEntries.query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace UniEngine\Engine\Modules\Settings\Utils\Queries;

/**
* @param array $params
* @param string $params['entryOwnerId']
* @param string[] $params['entriesIds']
*/
function deleteUserIgnoreEntries($params) {
$entryOwnerId = $params['entryOwnerId'];
$entriesIds = $params['entriesIds'];

$entriesIdsString = implode(', ', $entriesIds);
$entriesIdsCount = count($entriesIds);

$query = (
"DELETE FROM {{table}} " .
"WHERE " .
"`OwnerID` = {$entryOwnerId} AND " .
"`IgnoredID` IN ({$entriesIdsString}) " .
"LIMIT {$entriesIdsCount} " .
"; -- UniEngine\Engine\Modules\Settings\Utils\Queries\deleteUserIgnoreEntries"
);

doquery($query, 'ignoresystem');
}

?>
18 changes: 7 additions & 11 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,20 +828,16 @@
}
}

if(!empty($IgnoreSystem_Deleted))
{
$IgnoreSystem_Deleted_Count = count($IgnoreSystem_Deleted);
$IgnoreSystem_Deleted = implode(',', $IgnoreSystem_Deleted);
if (!empty($IgnoreSystem_Deleted)) {
Settings\Utils\Queries\deleteUserIgnoreEntries([
'entryOwnerId' => $_User['id'],
'entriesIds' => $IgnoreSystem_Deleted,
]);

$Query_DeleteIgnores = '';
$Query_DeleteIgnores .= "DELETE FROM {{table}} WHERE ";
$Query_DeleteIgnores .= "`OwnerID` = {$_User['id']} AND `IgnoredID` IN ({$IgnoreSystem_Deleted}) LIMIT {$IgnoreSystem_Deleted_Count};";
doquery($Query_DeleteIgnores, 'ignoresystem');
$IgnoreSystem_Deleted_Count = count($IgnoreSystem_Deleted);

$InfoMsgs[] = sprintf($_Lang['Ignore_DeletedXUsers'], $IgnoreSystem_Deleted_Count);
}
else
{
} else {
$WarningMsgs[] = $_Lang['Ignore_NothingDeleted'];
}
}
Expand Down

0 comments on commit 529315d

Please sign in to comment.