Skip to content

Commit

Permalink
Merge pull request #553 from FreshPorts/542-notification-new-package-…
Browse files Browse the repository at this point in the history
…available

542 notification new package available
  • Loading branch information
dlangille authored Mar 11, 2024
2 parents 2860ae1 + 2a5bd98 commit 6a1e549
Show file tree
Hide file tree
Showing 13 changed files with 620 additions and 40 deletions.
78 changes: 78 additions & 0 deletions classes/abi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
#
# $Id: watch_lists.php,v 1.2 2006-12-17 11:37:22 dan Exp $
#
# Copyright (c) 1998-2005 DVL Software Limited
#

require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_list.php');

// base class for fetching watch lists
class ABI {

var $dbh;
var $LocalResult;
var $Debug;

var $id;
var $name;

function __construct($dbh) {
$this->dbh = $dbh;
$this->Debug = 0;
}

function Fetch() {
$this->Debug = 0;

$sql = "-- " . __FILE__ . '::' . __FUNCTION__ . '
SELECT id,
name
FROM abi
WHERE active
ORDER BY name';
$params = array();

if ($this->Debug) {
echo 'ABI::Fetch sql = <pre>' . $sql . '</pre>';
}

$this->LocalResult = pg_query_params($this->dbh, $sql, $params);
if ($this->LocalResult) {
$numrows = pg_num_rows($this->LocalResult);
# echo "That would give us $numrows rows";
} else {
$numrows = -1;
echo 'pg_query_params failed: ' . $sql;
}

return $numrows;
}

function FetchNth($N) {
#
# call Fetch first.
# then call this function N times, where N is the number
# returned by Fetch
#

# echo "fetching row $N<br>";

$myrow = pg_fetch_array($this->LocalResult, $N);
$this->PopulateValues($myrow);

return 1;
}

function PopulateValues($myrow) {
#
# call Fetch first.
# then call this function N times, where N is the number
# returned by Fetch.
#

$this->id = $myrow["id"];
$this->name = $myrow["name"];
}

}
6 changes: 3 additions & 3 deletions classes/port-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -1738,14 +1738,14 @@ function LinkToPort() {
return $HTML;
}

function ReplaceWatchListToken($OnWatchList, $HTML, $ElementID) {
function ReplaceWatchListToken($OnWatchList, $HTML, $ElementID, $wlid = 0) {
$Watch_HTML = '';

if ($this->User && $this->User->id && ($this->ShowEverything || $this->ShowWatchListStatus)) {
if ($OnWatchList) {
$Watch_HTML .= freshports_Watch_Link_Remove($this->User->watch_list_add_remove, $OnWatchList, $ElementID);
$Watch_HTML .= freshports_Watch_Link_Remove($this->User->watch_list_add_remove, $OnWatchList, $ElementID, $wlid);
} else {
$Watch_HTML .= freshports_Watch_Link_Add ($this->User->watch_list_add_remove, $OnWatchList, $ElementID);
$Watch_HTML .= freshports_Watch_Link_Add ($this->User->watch_list_add_remove, $OnWatchList, $ElementID, $wlid);
}
}

Expand Down
167 changes: 167 additions & 0 deletions classes/report_subscriptions_abi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
#
# Copyright (c) 2024 Dan Langille
#

// base class for subscriptions to package notifications
class report_subscriptions_abi {

var $dbh;
var $LocalResult;

var $Debug;

var $user_id;
var $watch_list_id;
var $abi_id;
var $package_set;

var $abi_name;
var $watch_list_name;

function __construct($dbh) {
$this->dbh = $dbh;
$this->Debug = 1;
}

function DeleteAllSubscriptions($UserID) {
#
# Delete a the subscriptions for a user
#
unset($return);

$query = '
DELETE FROM report_subscriptions_abi
WHERE user_id = $1';

if ($this->Debug) echo $query;
$result = pg_query_params($this->dbh, $query, array($UserID));

# that worked and we updated exactly one row
if ($result) {
$return = 1;
}

return $return;
}

function Fetch($UserID) {

$this->Debug = 0;

$sql = "-- " . __FILE__ . '::' . __FUNCTION__ . '
SELECT RSA.user_id,
RSA.abi_id,
abi.name AS abi_name,
RSA.package_set,
WL.id AS watch_list_id,
WL.name AS watch_list_name
FROM report_subscriptions_abi RSA JOIN abi on RSA.abi_id = abi.id
JOIN watch_list WL ON RSA.watch_list_id = WL.id
WHERE RSA.user_id = $1
ORDER BY watch_list_name, abi_name';

if ($this->Debug) {
echo 'WatchLists::Fetch sql = <pre>' . $sql . '</pre>';
}

$this->LocalResult = pg_query_params($this->dbh, $sql, array($UserID));
if ($this->LocalResult) {
$numrows = pg_num_rows($this->LocalResult);
# echo "That would give us $numrows rows";
} else {
$numrows = -1;
echo 'pg_query_params failed: ' . $sql;
}

return $numrows;
}

function Save($UserID, $watch_list_id, $abi_id, $package_set) {
#
# Save the list of ABI/watch list combinations.
# abi_ids is an array of "$abi_id:$watch_list"
#
GLOBAL $Sequence_Watch_List_ID;

$return = 0;

# insert only that user owns that watch list.
$query = '
insert into report_subscriptions_abi(user_id, watch_list_id, abi_id, package_set)
select $1, $2, $3, $4::package_sets
from watch_list
where id = $2 and user_id = $1
on conflict on constraint report_subscriptions_abi_user_abi_watch_pk do nothing';
if ($this->Debug) echo "<pre>$query</pre>";

$this->LocalResult = pg_query_params($this->dbh, $query, array($UserID, $watch_list_id, $abi_id, $package_set));
if ($this->LocalResult) {
$return = 1;
} else {
$return = 1;
}
}
function Delete($UserID, $watch_list_id, $abi_id, $package_set) {
#
# Save the list of ABI/watch list combinations.
# abi_ids is an array of "$abi_id:$watch_list"
#
GLOBAL $Sequence_Watch_List_ID;

$return = 0;

#
# The "subselect" ensures the user can only delete things from their
# own watch list
#
$query = '
DELETE from report_subscriptions_abi RSA
using watch_list WL
WHERE WL.user_id = $1
AND WL.id = $2
AND RSA.watch_list_id = WL.id
AND RSA.abi_id = $3
AND RSA.package_set = $4';


if ($this->Debug) echo "<pre>$query</pre>";

$this->LocalResult = pg_query_params($this->dbh, $query, array($UserID, $watch_list_id, $abi_id, $package_set));
if ($this->LocalResult) {
$return = 1;
} else {
$return = 1;
}
}

function FetchNth($N) {
#
# call Fetch first.
# then call this function N times, where N is the number
# returned by Fetch
#

# echo "fetching row $N<br>";

$myrow = pg_fetch_array($this->LocalResult, $N);
$this->PopulateValues($myrow);

return $myrow;
}

function PopulateValues($myrow) {
#
# call Fetch first.
# then call this function N times, where N is the number
# returned by Fetch.
#

$this->user_id = $myrow['user_id'];
$this->watch_list_id = $myrow['watch_list_id'];
$this->abi_id = $myrow['abi_id'];
$this->package_set = $myrow['package_set'];
$this->abi_name = $myrow['abi_name'];
$this->watch_list_name = $myrow['watch_list_name'];
}
}
25 changes: 12 additions & 13 deletions classes/watch_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# Copyright (c) 1998-2005 DVL Software Limited
#

$Debug = 0;

// base class for a single watchlist
class WatchList {

var $dbh;
var $Debug;

var $id;
var $user_id;
Expand All @@ -25,6 +24,7 @@ class WatchList {

function __construct($dbh) {
$this->dbh = $dbh;
$this->Debug = 0;
}

function Create($UserID, $Name) {
Expand Down Expand Up @@ -125,7 +125,7 @@ function EmptyTheList($UserID, $WatchListID) {
# Empty a watch list (couldn't use empty, as that's reserved)
#
unset($return);
$Debug = 0;
$this->Debug = 0;

$query = '
DELETE FROM watch_list_element
Expand All @@ -134,7 +134,7 @@ function EmptyTheList($UserID, $WatchListID) {
AND watch_list.user_id = $2
AND watch_list_element.watch_list_id = watch_list.id';

if ($Debug) echo $query;
if ($this->Debug) echo $query;
$result = pg_query_params($this->dbh, $query, array($WatchListID, $UserID));

# that worked and we updated exactly one row
Expand All @@ -150,7 +150,7 @@ function EmptyTheListCategory($UserID, $WatchListID, $CategoryID) {
# Empty a watch list of all items within the supplied category
#
unset($return);
$Debug = 0;
$this->Debug = 0;

$query = '
DELETE FROM watch_list_element
Expand All @@ -162,7 +162,7 @@ function EmptyTheListCategory($UserID, $WatchListID, $CategoryID) {
AND watch_list.user_id = $3
AND watch_list_element.watch_list_id = watch_list.id';

if ($Debug) echo $query;
if ($this->Debug) echo $query;
$result = pg_query_params($this->dbh, $query, array($CategoryID, $WatchListID, $UserID));

# that worked and we updated exactly one row
Expand All @@ -178,21 +178,21 @@ function EmptyAllLists($UserID) {
# Empty all watch lists
#
unset($return);
$Debug = 0;
$this->Debug = 0;

$query = '
DELETE FROM watch_list_element
USING watch_list
WHERE watch_list.user_id = $1
AND watch_list_element.watch_list_id = watch_list.id';

if ($Debug) echo $query;
if ($this->Debug) echo $query;
$result = pg_query_params($this->dbh, $query, array($UserID));

# that worked and we updated exactly one row
if ($result) {
$return = pg_affected_rows($result);
if ($Debug) echo '<br>pg_affected_rows = ' . $return;
if ($this->Debug) echo '<br>pg_affected_rows = ' . $return;
}

return $return;
Expand All @@ -203,14 +203,13 @@ function Rename($UserID, $WatchListID, $NewName) {
# Delete a watch list
#
$return = null;
Global $Debug;

$query = '
UPDATE watch_list
SET name = $1
WHERE id = $2
AND watch_list.user_id = $3';
if ($Debug) echo $query;
if ($this->Debug) echo $query;
$result = pg_query_params($this->dbh, $query, array($NewName, $WatchListID, $UserID));

# that worked and we updated exactly one row
Expand All @@ -223,7 +222,7 @@ function Rename($UserID, $WatchListID, $NewName) {


function Fetch($UserID, $ID) {
$Debug = 0;
$this->Debug = 0;

$sql = '
SELECT id,
Expand All @@ -238,7 +237,7 @@ function Fetch($UserID, $ID) {

# echo '<pre>' . $sql . '</pre>';

if ($Debug) echo "WatchLists::Fetch sql = '$sql'<br>";
if ($this->Debug) echo "WatchLists::Fetch sql = '$sql'<br>";

if ($ID == '') {
syslog(LOG_NOTICE, "classes/watch_list.php::line 213 \$UserID='$UserID', \$ID='$ID'");
Expand Down
1 change: 1 addition & 0 deletions classes/watch_list_deleted_ports.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// base class for getting deleted ports on a watch list
class WatchListDeletedPorts {

var $dbh;
var $name_old;
var $category_old;
var $name_new;
Expand Down
Loading

0 comments on commit 6a1e549

Please sign in to comment.