Remove use of NULL_DATE constant in core

The NULL_DATE constant is defined conditionally in the DBA static class.
This causes issues with static analyzing tools like PHPStan, because
they can not really know if the constant is defined or not.

We could make PHPStan ignore this, but since there already is a
`get_null_date()` method on the `dba_driver` class, this patch
changes the code to use this method instead.

We could also use the public static attribute `$null_date` on the DBA
class directly, but using a method feels cleaner, and allows for making
the attribute private, or even removing it completely at some later
time.

I'm not removing the NULL_DATE constant for now, in case it is in use by
any extensions.
This commit is contained in:
Harald Eilertsen
2026-03-07 11:15:46 +01:00
parent ad85825cab
commit cbd208eea3
37 changed files with 128 additions and 94 deletions

View File

@@ -8,6 +8,7 @@
namespace Zotlabs\Module;
use DBA;
use Zotlabs\Lib\Config;
require_once('include/account.php');
@@ -90,7 +91,7 @@ class Admin extends \Zotlabs\Web\Controller {
$r = q("SELECT COUNT(CASE WHEN account_id > 0 THEN 1 ELSE NULL END) AS total, COUNT(CASE WHEN account_expires > %s THEN 1 ELSE NULL END) AS expiring, COUNT(CASE WHEN account_expires < %s AND account_expires > '%s' THEN 1 ELSE NULL END) AS expired, COUNT(CASE WHEN (account_flags & %d)>0 THEN 1 ELSE NULL END) AS blocked FROM account",
db_utcnow(),
db_utcnow(),
dbesc(NULL_DATE),
dbesc(DBA::$dba->get_null_date()),
intval(ACCOUNT_BLOCKED)
);
if ($r) {

View File

@@ -1,6 +1,7 @@
<?php
namespace Zotlabs\Module;
use DBA;
class Changeaddr extends \Zotlabs\Web\Controller {
@@ -29,7 +30,7 @@ class Changeaddr extends \Zotlabs\Web\Controller {
if(! ($x && $x['account']))
return;
if($account['account_password_changed'] > NULL_DATE) {
if($account['account_password_changed'] > DBA::$dba->get_null_date()) {
$d1 = datetime_convert('UTC','UTC','now - 48 hours');
if($account['account_password_changed'] > $d1) {
notice( t('Channel name changes are not allowed within 48 hours of changing the account password.') . EOL);

View File

@@ -3,6 +3,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libsync;
use Zotlabs\Access\AccessList;
@@ -300,7 +301,7 @@ class Channel_calendar extends Controller {
from event left join item on item.resource_id = event.event_hash
where event.uid = %d and event.dtstart > '%s' and event.dtend > event.dtstart",
intval(local_channel()),
dbesc(NULL_DATE)
dbesc(DBA::$dba->get_null_date())
);
}
else {

View File

@@ -2,6 +2,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use Zotlabs\Lib\Config;
use Zotlabs\Web\Controller;
@@ -232,7 +233,7 @@ class Dirsearch extends Controller {
$spkt = array('transactions' => array());
$r = q("SELECT * FROM updates WHERE ud_update = 0 AND ud_last = '%s' AND ud_date >= '%s' ORDER BY ud_date DESC",
dbesc(NULL_DATE),
dbesc(DBA::$dba->get_null_date()),
dbesc($sync)
);

View File

@@ -2,6 +2,7 @@
namespace Zotlabs\Module;
use DBA;
use Zotlabs\Lib\PConfig;
use Zotlabs\Web\Controller;
@@ -21,7 +22,7 @@ class Feed extends Controller {
killme();
}
$params['begin'] = $_REQUEST['date_begin'] ?? NULL_DATE;
$params['begin'] = $_REQUEST['date_begin'] ?? DBA::$dba->get_null_date();
$params['end'] = $_REQUEST['date_end'] ?? '';
$params['type'] = 'xml';
$params['pages'] = ((!empty($_REQUEST['pages'])) ? intval($_REQUEST['pages']) : 0);

View File

@@ -7,6 +7,7 @@ require_once('include/import.php');
require_once('include/perm_upgrade.php');
use App;
use DBA;
use URLify;
use Zotlabs\Daemon\Master;
use Zotlabs\Lib\Config;
@@ -331,7 +332,7 @@ class Import extends Controller {
else {
$photos = import_xchan_photo($xchan['xchan_photo_l'], $xchan['xchan_hash']);
if ($photos[4])
$photodate = NULL_DATE;
$photodate = DBA::$dba->get_null_date();
else
$photodate = $xchan['xchan_photo_date'];

View File

@@ -3,6 +3,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use URLify;
use Zotlabs\Lib\Config;
use Zotlabs\Lib\IConfig;
@@ -209,7 +210,7 @@ class Item extends Controller {
}
$expires = NULL_DATE;
$expires = DBA::$dba->get_null_date();
$route = '';
$parent_item = null;
@@ -559,7 +560,7 @@ class Item extends Controller {
if (!empty($_POST['expire'])) {
$expires = datetime_convert(date_default_timezone_get(), 'UTC', $_POST['expire']);
if ($expires <= datetime_convert())
$expires = NULL_DATE;
$expires = DBA::$dba->get_null_date();
}
}
@@ -801,7 +802,7 @@ class Item extends Controller {
$item_origin = (($origin) ? 1 : 0);
$item_consensus = (($consensus) ? 1 : 0);
$item_nocomment = (($nocomment) ? 1 : 0);
$comments_closed = (($nocomment) ? $comments_closed : NULL_DATE);
$comments_closed = (($nocomment) ? $comments_closed : DBA::$dba->get_null_date());
// determine if this is a wall post
@@ -875,7 +876,7 @@ class Item extends Controller {
if ($obj['endTime']) {
$d = datetime_convert('UTC','UTC', $obj['endTime']);
if ($d > NULL_DATE) {
if ($d > DBA::$dba->get_null_date()) {
$comments_closed = $d;
}
}

View File

@@ -3,6 +3,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Config;
@@ -47,7 +48,7 @@ class Outbox extends Controller {
$params = [];
$params['begin'] = ((x($_REQUEST, 'date_begin')) ? $_REQUEST['date_begin'] : NULL_DATE);
$params['begin'] = ((x($_REQUEST, 'date_begin')) ? $_REQUEST['date_begin'] : DBA::$dba->get_null_date());
$params['end'] = ((x($_REQUEST, 'date_end')) ? $_REQUEST['date_end'] : '');
$params['type'] = 'json';
$params['pages'] = ((x($_REQUEST, 'pages')) ? intval($_REQUEST['pages']) : 0);

View File

@@ -1,6 +1,7 @@
<?php
namespace Zotlabs\Module;
use DBA;
use Zotlabs\Lib\Config;
use Zotlabs\Lib\Libsync;
@@ -340,7 +341,7 @@ class Profiles extends \Zotlabs\Web\Controller {
$with = ((x($_POST,'with')) ? escape_tags(trim($_POST['with'])) : '');
if(! strlen($howlong))
$howlong = NULL_DATE;
$howlong = DBA::$dba->get_null_date();
else
$howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
@@ -774,7 +775,7 @@ class Profiles extends \Zotlabs\Web\Controller {
'$marital' => marital_selector($r[0]['marital']),
'$marital_min' => marital_selector_min($r[0]['marital']),
'$with' => array('with', t("Who (if applicable)"), $r[0]['partner'], t('Examples: cathy123, Cathy Williams, cathy@example.com')),
'$howlong' => array('howlong', t('Since (date)'), ($r[0]['howlong'] <= NULL_DATE ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong']))),
'$howlong' => array('howlong', t('Since (date)'), ($r[0]['howlong'] <= DBA::$dba->get_null_date() ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong']))),
'$sexual' => sexpref_selector($r[0]['sexual']),
'$sexual_min' => sexpref_selector_min($r[0]['sexual']),
'$about' => array('about', t('Tell us about yourself'), $r[0]['about']),

View File

@@ -1,6 +1,7 @@
<?php
namespace Zotlabs\Module;
use DBA;
class Removeaccount extends \Zotlabs\Web\Controller {
@@ -29,7 +30,7 @@ class Removeaccount extends \Zotlabs\Web\Controller {
if(! ($x && $x['account']))
return;
if($account['account_password_changed'] > NULL_DATE) {
if($account['account_password_changed'] > DBA::$dba->get_null_date()) {
$d1 = datetime_convert('UTC','UTC','now - 48 hours');
if($account['account_password_changed'] > $d1) {
notice( t('Account removals are not allowed within 48 hours of changing the account password.') . EOL);

View File

@@ -1,6 +1,7 @@
<?php
namespace Zotlabs\Module;
use DBA;
class Removeme extends \Zotlabs\Web\Controller {
@@ -29,7 +30,7 @@ class Removeme extends \Zotlabs\Web\Controller {
if(! ($x && $x['account']))
return;
if($account['account_password_changed'] > NULL_DATE) {
if($account['account_password_changed'] > DBA::$dba->get_null_date()) {
$d1 = datetime_convert('UTC','UTC','now - 48 hours');
if($account['account_password_changed'] > $d1) {
notice( t('Channel removals are not allowed within 48 hours of changing the account password.') . EOL);

View File

@@ -3,6 +3,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\Config;
use Zotlabs\Web\Controller;
@@ -136,7 +137,7 @@ class Sse extends Controller {
session_reset();
XConfig::Set(self::$ob_hash, 'sse', 'timestamp', NULL_DATE);
XConfig::Set(self::$ob_hash, 'sse', 'timestamp', DBA::$dba->get_null_date());
XConfig::Set(self::$ob_hash, 'sse', 'notifications', []);
if (ob_get_length() > 0) {

View File

@@ -3,21 +3,21 @@ namespace Zotlabs\Module;
require_once('include/event.php');
use DBA;
class Tasks extends \Zotlabs\Web\Controller {
function init() {
// logger('request: ' . print_r($_REQUEST,true));
$arr = array();
if(argc() > 1 && argv(1) === 'fetch') {
if(argc() > 1 && argv(1) === 'fetch') {
if(argc() > 2 && argv(2) === 'all')
$arr['all'] = 1;
$x = tasks_fetch($arr);
$x['html'] = '';
if($x['tasks']) {
@@ -53,7 +53,7 @@ class Tasks extends \Zotlabs\Web\Controller {
$event = $r[0];
if($event['event_status'] === 'COMPLETED') {
$event['event_status'] = 'IN-PROCESS';
$event['event_status_date'] = NULL_DATE;
$event['event_status_date'] = DBA::$dba->get_null_date();
$event['event_percent'] = 0;
$event['event_sequence'] = $event['event_sequence'] + 1;
$event['edited'] = datetime_convert();

View File

@@ -3,6 +3,7 @@
namespace Zotlabs\Module;
use App;
use DBA;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\AccessList;
@@ -84,7 +85,7 @@ class Tokens extends Controller {
if(trim($_POST['expires']))
$expires = datetime_convert(date_default_timezone_get(),'UTC',$_POST['expires']);
else
$expires = NULL_DATE;
$expires = DBA::$dba->get_null_date();
$max_atokens = service_class_fetch($channel['channel_id'],'access_tokens');
if($max_atokens) {
$r = q("select count(atoken_id) as total where atoken_uid = %d",
@@ -290,7 +291,7 @@ class Tokens extends Controller {
'$atoken' => $atoken,
'$name' => array('name', t('Login Name') . ' <span class="required">*</span>', $atoken['atoken_name'] ?? '',''),
'$token'=> array('token', t('Login Password') . ' <span class="required">*</span>', $atoken['atoken_token'] ?? new_token(), ''),
'$expires'=> array('expires', t('Expires (yyyy-mm-dd)'), ((isset($atoken['atoken_expires']) && $atoken['atoken_expires'] > NULL_DATE) ? datetime_convert('UTC',date_default_timezone_get(),$atoken['atoken_expires']) : ''), ''),
'$expires'=> array('expires', t('Expires (yyyy-mm-dd)'), ((isset($atoken['atoken_expires']) && $atoken['atoken_expires'] > DBA::$dba->get_null_date()) ? datetime_convert('UTC',date_default_timezone_get(),$atoken['atoken_expires']) : ''), ''),
'$submit' => t('Submit'),
'$delete' => t('Delete')
));