Files
zemailnator/app/Models/Meta.php
idevakk 3706072ce5 fix: resolve PSR-4 autoloading and test failures
- Add proper Tests\ namespace to all test classes in tests/Feature and tests/Unit
  - Split RemainingModelsTest.php into separate files (PSR-4 compliance)
  - Create missing factories: MetaFactory, RemoteEmailFactory
  - Add HasFactory trait to RemoteEmail model
  - Add missing ReflectionClass imports to test files
  - Fix mass assignment issues in Meta and RemoteEmail models
  - Override database connection for RemoteEmail in testing environment
  - Fix DateTime comparison precision issues in tests
2025-11-13 09:49:21 -08:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Meta extends Model {
use HasFactory;
protected $fillable = [
'key',
'value',
];
public function incrementMeta($value = 1) {
$this->value = $this->value + $value;
$this->save();
return true;
}
public static function incrementEmailIdsCreated($value = 1): bool
{
$meta = Meta::where('key', 'email_ids_created')->first();
if ($meta) {
$meta->incrementMeta($value);
return true;
}
return false;
}
public static function incrementMessagesReceived($value = 1): bool
{
$meta = Meta::where('key', 'messages_received')->first();
if ($meta) {
$meta->incrementMeta($value);
return true;
}
return false;
}
public static function getEmailIdsCreated() {
$meta = Meta::where('key', 'email_ids_created')->first();
if ($meta) {
return $meta->value;
}
return "NaN";
}
public static function getMessagesReceived() {
$meta = Meta::where('key', 'messages_received')->first();
if ($meta) {
return $meta->value;
}
return "NaN";
}
}