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

@@ -4,6 +4,7 @@
* @brief Items related functions.
*/
use DBA;
use Zotlabs\Lib\Config;
use Zotlabs\Lib\Crypto;
use Zotlabs\Lib\Enotify;
@@ -232,7 +233,7 @@ function comments_are_now_closed($item) {
return $x['closed'];
}
if($item['comments_closed'] > NULL_DATE) {
if($item['comments_closed'] > DBA::$dba->get_null_date()) {
$d = datetime_convert();
if($d > $item['comments_closed'])
return true;
@@ -732,14 +733,14 @@ function get_item_elements($x,$allow_code = false) {
$arr['expires'] = ((!empty($x['expires']) && $x['expires'])
? datetime_convert('UTC','UTC',$x['expires'])
: NULL_DATE);
: DBA::$dba->get_null_date());
$arr['commented'] = ((!empty($x['commented']) && $x['commented'])
? datetime_convert('UTC','UTC',$x['commented'])
: $arr['created']);
$arr['comments_closed'] = ((!empty($x['comments_closed']) && $x['comments_closed'])
? datetime_convert('UTC','UTC',$x['comments_closed'])
: NULL_DATE);
: DBA::$dba->get_null_date());
$arr['title'] = (($x['title']) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8',false) : '');
@@ -1210,7 +1211,7 @@ function encode_item($item,$mirror = false,$zap_compat = false) {
if($y = encode_item_flags($item))
$x['flags'] = $y;
if($item['comments_closed'] > NULL_DATE)
if($item['comments_closed'] > DBA::$dba->get_null_date())
$x['comments_closed'] = $item['comments_closed'];
$x['public_scope'] = $item['public_policy'];
@@ -1773,9 +1774,9 @@ function item_store($arr, $allow_exec = false, $deliver = true, $addAndSync = tr
$arr['owner_xchan'] = ((!empty($arr['owner_xchan'])) ? notags(trim($arr['owner_xchan'])) : '');
$arr['created'] = ((!empty($arr['created']) !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['edited'] = ((!empty($arr['edited']) !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['expires'] = ((!empty($arr['expires']) !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE);
$arr['expires'] = ((!empty($arr['expires']) !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : DBA::$dba->get_null_date());
$arr['commented'] = ((!empty($arr['commented']) !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert());
$arr['comments_closed'] = ((!empty($arr['comments_closed']) !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : NULL_DATE);
$arr['comments_closed'] = ((!empty($arr['comments_closed']) !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : DBA::$dba->get_null_date());
$arr['html'] = ((array_key_exists('html',$arr)) ? $arr['html'] : '');
if($deliver) {
@@ -4440,7 +4441,7 @@ function zot_feed($uid, $observer_hash, $arr) {
}
if (!$mindate)
$mindate = NULL_DATE;
$mindate = DBA::$dba->get_null_date();
$mindate = dbesc($mindate);
@@ -4458,7 +4459,7 @@ function zot_feed($uid, $observer_hash, $arr) {
$limit = " LIMIT 5000 ";
if ($mindate > NULL_DATE) {
if ($mindate > DBA::$dba->get_null_date()) {
$sql_extra .= " and ( created > '$mindate' or changed > '$mindate' ) ";
}