public/lib/notifications.php
/*
    * @abstract If the database has been setup and the notification updates installed, update the manager notification
    *  message to say how many albums have expired on the playlist and are ready to be converted to the library.
    */
@abstract If the database has been setup and the notification updates installed, update the manager notification
message to say how many albums have expired on the playlist and are ready to be converted to the library.
@abstract If the database has been setup and the notification updates installed update the manager notification message to say how many albums have expired on the playlist and are ready to be converted to the library .
public function checkConvert($notifyMgmt=TRUE) {
	$setup = FALSE;
	$stmt = $this->db->query("SHOW TABLES;");
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC))
	    if (array_values($row)[0] == 'notification')
		$setup = TRUE;
	if (!$setup)
	    return;
	$updated = FALSE;
	$stmt = $this->db->query("SHOW COLUMNS FROM notification WHERE Field='path';");
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC))
	    if ($row['Field'] == 'path')
		$updated = TRUE;
	if (!$updated)
	    return;
	$playlist = new \TPS\playlist();
	$numExpired = sizeof($playlist->getExpiredAlbums());
	if ($numExpired > 0) {
	    $stmt = $this->db->query("SELECT message FROM notification WHERE tag='expired albums';");
	    $alreadyNotifiedOf = 0;
            while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
		preg_match('/[0-9]+/', $row['message'], $num);
		$alreadyNotifiedOf = $num[0];
	    }
	    if ($alreadyNotifiedOf != $numExpired) {
		if ($numExpired == 1)
		    $msg = "1 expired album is on the playlist";
		else
		    $msg = "$numExpired expired albums are on the playlist";
	        $this->db->query("DELETE FROM notification WHERE tag='expired albums';");
	        $this->db->query("INSERT INTO notification (message, time, tag, path) VALUES ('" .
				 $msg . "', NOW(), 'expired albums', '/playlist/?expired=true');");
	        if (!$notifyMgmt)
		    $this->db->query("UPDATE notification SET acknowledged=NOW() WHERE notificationid=LAST_INSERT_ID();");
	    }
	}
	$traffic = new \TPS\traffic();
    $numExpired = 0;
	if ($numExpired > 0) {
	    $stmt = $this->db->query("SELECT message FROM notification WHERE tag='expired contracts';");
	    $alreadyNotifiedOf = 0;
            while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
		preg_match('/[0-9]+/', $row['message'], $num);
		$alreadyNotifiedOf = $num[0];
	    }
	    if ($alreadyNotifiedOf != $numExpired) {
		if ($numExpired == 1)
		    $msg = "1 expired contract is active";
		else
		    $msg = "$numExpired expired contracts are active";
	        $this->db->query("DELETE FROM notification WHERE tag='expired contracts';");
	        $this->db->query("INSERT INTO notification (message, time, tag, path) VALUES ('" .
				 $msg . "', NOW(), 'expired contracts', '/traffic/search/?expired=true');");
	        if (!$notifyMgmt)
		    $this->db->query("UPDATE notification SET acknowledged=NOW() WHERE notificationid=LAST_INSERT_ID();");
	    }
	}
    }
public function checkConvert ( $ notifyMgmt = TRUE ) { $ setup = FALSE ; $ stmt = $ this -> db -> query ( " SHOW TABLES; " ) ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) if ( array_values ( $ row ) [ 0 ] == 'notification' ) $ setup = TRUE ; if ( ! $ setup ) return ; $ updated = FALSE ; $ stmt = $ this -> db -> query ( " SHOW COLUMNS FROM notification WHERE Field='path'; " ) ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) if ( $ row [ 'Field' ] == 'path' ) $ updated = TRUE ; if ( ! $ updated ) return ; $ playlist = new \ TPS \ playlist ( ) ; $ numExpired = sizeof ( $ playlist -> getExpiredAlbums ( ) ) ; if ( $ numExpired > 0 ) { $ stmt = $ this -> db -> query ( " SELECT message FROM notification WHERE tag='expired albums'; " ) ; $ alreadyNotifiedOf = 0 ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { preg_match ( '/[0-9]+/' , $ row [ 'message' ] , $ num ) ; $ alreadyNotifiedOf = $ num [ 0 ] ; } if ( $ alreadyNotifiedOf != $ numExpired ) { if ( $ numExpired == 1 ) $ msg = " 1 expired album is on the playlist " ; else $ msg = " $ numExpired  expired albums are on the playlist " ; $ this -> db -> query ( " DELETE FROM notification WHERE tag='expired albums'; " ) ; $ this -> db -> query ( " INSERT INTO notification (message, time, tag, path) VALUES (' " . $ msg . " ', NOW(), 'expired albums', '/playlist/?expired=true'); " ) ; if ( ! $ notifyMgmt ) $ this -> db -> query ( " UPDATE notification SET acknowledged=NOW() WHERE notificationid=LAST_INSERT_ID(); " ) ; } } $ traffic = new \ TPS \ traffic ( ) ; $ numExpired = 0 ; if ( $ numExpired > 0 ) { $ stmt = $ this -> db -> query ( " SELECT message FROM notification WHERE tag='expired contracts'; " ) ; $ alreadyNotifiedOf = 0 ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { preg_match ( '/[0-9]+/' , $ row [ 'message' ] , $ num ) ; $ alreadyNotifiedOf = $ num [ 0 ] ; } if ( $ alreadyNotifiedOf != $ numExpired ) { if ( $ numExpired == 1 ) $ msg = " 1 expired contract is active " ; else $ msg = " $ numExpired  expired contracts are active " ; $ this -> db -> query ( " DELETE FROM notification WHERE tag='expired contracts'; " ) ; $ this -> db -> query ( " INSERT INTO notification (message, time, tag, path) VALUES (' " . $ msg . " ', NOW(), 'expired contracts', '/traffic/search/?expired=true'); " ) ; if ( ! $ notifyMgmt ) $ this -> db -> query ( " UPDATE notification SET acknowledged=NOW() WHERE notificationid=LAST_INSERT_ID(); " ) ; } } }
@abstract If the database has been setup and the notification updates installed, update the manager notification
  message to say how many albums have expired on the playlist and are ready to be converted to the library.
@abstract If the database has been setup and the notification updates installed update the manager notification message to say how many albums have expired on the playlist and are ready to be converted to the library .
// Ensure the database has been setup // Ensure NOTIFICATION_UPDATE_1 has been installed // Update the notification message to match the number of expired albums if it has changed since last time // Update the notification message to match the number of expired contracts if it has changed since last time // $numExpired = sizeof($traffic->getExpiredContracts());