Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/docker/ci/smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ function setting(string $name)
check('one document seeded', count_rows('site_content') === 1, 'rows: ' . count_rows('site_content'));
check('the document is the install success page', ($home['alias'] ?? '') === 'minimal-base', 'alias: ' . ($home['alias'] ?? 'none'));
check('the document uses the seeded template', (int) ($home['template'] ?? 0) === 1);
$templateSource = $pdo->query('SELECT templatesource FROM ' . t('site_templates') . ' WHERE id = 1')->fetchColumn();
check('the minimal template uses database rendering', $templateSource === 'db', 'source: ' . ($templateSource ?: 'empty'));
}
check('the document is published', (int) ($home['published'] ?? 0) === 1);
check('a template was seeded', count_rows('site_templates') >= 1);
Expand Down
1 change: 1 addition & 0 deletions core/database/seeders/SiteTemplatesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function run(): void
[
'templatename' => 'Minimal Template',
'templatealias' => '',
'templatesource' => 'db',
'description' => 'Default minimal empty template (content returned only)',
'editor_type' => 0,
'category' => 0,
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/ActiveUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
class ActiveUser extends Eloquent\Model
{
protected $table = 'active_users';

protected $primaryKey = 'sid';
public $incrementing = false;
public $timestamps = false;
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/ActiveUserLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class ActiveUserLock extends Eloquent\Model
{
protected $table = 'active_user_locks';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/ActiveUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
class ActiveUserSession extends Eloquent\Model
{
protected $table = 'active_user_sessions';

protected $primaryKey = 'sid';
public $incrementing = false;
public $timestamps = false;
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Category extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'categories';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/DocumentGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class DocumentGroup extends Eloquent\Model
{
protected $table = 'document_groups';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/DocumentgroupName.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class DocumentgroupName extends Eloquent\Model
{
protected $table = 'documentgroup_names';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/FileGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class FileGroup extends Eloquent\Model
{
protected $table = 'file_groups';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/MemberGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class MemberGroup extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'member_groups';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/MembergroupName.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class MembergroupName extends Eloquent\Model
{
protected $table = 'membergroup_names';

public $timestamps = false;

protected $fillable = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Permissions extends Eloquent\Model
{
use ManagerActions;

protected $table = 'permissions';

protected $managerActionsMap = [
'actions.cancel' => 86,
'actions.new' => 135,
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/PermissionsGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PermissionsGroups extends Eloquent\Model
{
use ManagerActions;

protected $table = 'permissions_groups';

protected $managerActionsMap = [
'actions.cancel' => 86,
'actions.new' => 136,
Expand Down
1 change: 1 addition & 0 deletions core/src/Models/RolePermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
class RolePermissions extends Eloquent\Model
{
protected $table = 'role_permissions';

protected $fillable = [
'permission',
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteHtmlsnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class SiteHtmlsnippet extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_htmlsnippets';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SiteModule extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_modules';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SitePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SitePlugin extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_plugins';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SitePluginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SitePluginEvent extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'site_plugin_events';

public $incrementing = false;
public $timestamps = false;

Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SiteSnippet extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_snippets';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class SiteTemplate extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_templates';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteTmplvar.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SiteTmplvar extends Eloquent\Model
use Traits\Models\ManagerActions,
Traits\Models\TimeMutator;

protected $table = 'site_tmplvars';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteTmplvarContentvalue.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
class SiteTmplvarContentvalue extends Eloquent\Model
{
protected $table = 'site_tmplvar_contentvalues';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SiteTmplvarTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class SiteTmplvarTemplate extends Eloquent\Model
{
protected $table = 'site_tmplvar_templates';

public $incrementing = false;
public $timestamps = false;

Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SystemEventname.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
class SystemEventname extends Eloquent\Model
{
protected $table = 'system_eventnames';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/SystemSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class SystemSetting extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'system_settings';

protected $primaryKey = 'setting_name';
public $incrementing = false;
public $timestamps = false;
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class User extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'users';

public $timestamps = false;

protected $hidden = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/UserAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class UserAttribute extends Eloquent\Model
{
use Traits\Models\TimeMutator;

protected $table = 'user_attributes';

const CREATED_AT = 'createdon';
const UPDATED_AT = 'editedon';
protected $dateFormat = 'U';
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/UserRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class UserRole extends Eloquent\Model
{
use Traits\Models\ManagerActions;

protected $table = 'user_roles';

public $timestamps = false;

protected $casts = [
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/UserRoleVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
class UserRoleVar extends Eloquent\Model
{
protected $table = 'user_role_vars';

public $incrementing = false;
public $timestamps = false;

Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/UserSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class UserSetting extends Eloquent\Model
{
protected $table = 'user_settings';

protected $primaryKey = null;
public $incrementing = false;
public $timestamps = false;
Expand Down
2 changes: 2 additions & 0 deletions core/src/Models/UserValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class UserValue extends Model
{
protected $table = 'user_values';

public $timestamps = false;

protected $casts = [
Expand Down
41 changes: 41 additions & 0 deletions core/src/Traits/Models/SoftDeletes.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace EvolutionCMS\Traits\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\SoftDeletes as BaseSoftDeletes;
use EvolutionCMS\Shit\SoftDeletingScope;

Expand Down Expand Up @@ -36,4 +37,44 @@ public function restore()

return $result;
}

/**
* Keep the deleted-at column as its stored Unix timestamp in array form.
*
* The base trait casts that column to datetime, so toArray() would build a
* Carbon instance only to print it as an ISO string: every uncached page
* paid for loading Carbon, and templates got a value unlike every other
* date field. Reading the attribute still returns Carbon.
*
* @param array<string, mixed> $attributes
* @param array<int, string> $mutatedAttributes
* @return array<string, mixed>
*/
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
{
$column = $this->getDeletedAtColumn();
if (!array_key_exists($column, $attributes)
|| in_array($column, $mutatedAttributes, true)
|| ($this->getCasts()[$column] ?? null) !== 'datetime'
) {
return parent::addCastAttributesToArray($attributes, $mutatedAttributes);
}

$raw = $attributes[$column];
if ($raw instanceof DateTimeInterface) {
$raw = $raw->getTimestamp();
} elseif (is_numeric($raw)) {
$raw = (int) $raw;
}

// The parent only rewrites keys it is given, so the column goes back
// where it was and the array keeps its order.
$position = array_search($column, array_keys($attributes), true);
unset($attributes[$column]);
$attributes = parent::addCastAttributesToArray($attributes, $mutatedAttributes);

return array_slice($attributes, 0, $position, true)
+ [$column => $raw]
+ array_slice($attributes, $position, null, true);
}
}
63 changes: 63 additions & 0 deletions core/tests/Mocks/default_site_template_seeder_worker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Illuminate\Database {
class Seeder
{
}
}

namespace Illuminate\Support\Facades {
final class Schema
{
public static function hasTable(string $table): bool
{
return $table === 'site_templates';
}
}

final class DB
{
public static array $inserted = [];

public static function table(string $table): FakeTable
{
return new FakeTable($table);
}
}

final class FakeTable
{
public function __construct(private string $name)
{
}

public function count(): int
{
return 0;
}

public function delete(): int
{
DB::$inserted[$this->name] = [];

return 0;
}

public function insert(array $rows): void
{
DB::$inserted[$this->name] = $rows;
}
}
}

namespace {
require $argv[1];

$seederClass = $argv[2];
(new $seederClass())->run();

echo json_encode(
\Illuminate\Support\Facades\DB::$inserted['site_templates'][0] ?? [],
JSON_THROW_ON_ERROR
);
}
Loading
Loading