Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function up()
$table->json('data');
$table->json('aux');
$table->string('editor');
$table->timestamp('created_at', 6);
$table->timestamp('created_at', 3);

$table->index(['versionable_id', 'versionable_type', 'created_at', 'tenant_id'], 'idx_versions_id_type_created_tenantid');
$table->index(['publish_at', 'published']);
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Mutations/AddElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __invoke( $rootValue, array $args ) : Element

$version->files()->attach( $args['files'] ?? [] );

return $element->refresh();
return $element;
}, 3 );
}
}
2 changes: 1 addition & 1 deletion src/GraphQL/Mutations/AddFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __invoke( $rootValue, array $args ) : File
],
] );

return $file->refresh();
return $file;
}, 3 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Mutations/AddPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __invoke( $rootValue, array $args ) : Page
$version->elements()->attach( $args['elements'] ?? [] );
$version->files()->attach( $args['files'] ?? [] );

return $page->refresh();
return $page;
}, 3 );
} );
}
Expand Down
27 changes: 27 additions & 0 deletions src/Models/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

use Aimeos\Cms\Concerns\Tenancy;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Laravel\Scout\Attributes\SearchUsingFullText;
use Laravel\Scout\Searchable;
use Illuminate\Support\Str;


/**
Expand Down Expand Up @@ -77,6 +79,17 @@ public function getConnectionName() : string
}


/**
* Generate a new unique key for the model.
*
* @return string
*/
public function newUniqueId()
{
return strtoupper( (string) Str::uuid7() );
}


/**
* Get the name of the index associated with the model.
*/
Expand All @@ -97,4 +110,18 @@ public function toSearchableArray(): array
'content' => $this->content
];
}


/**
* Interact with the "id" property.
*
* @return Attribute Eloquent attribute for the "id" property
*/
protected function id(): Attribute
{
return Attribute::make(
get: fn( $value ) => strtoupper( $value ),
set: fn( $value ) => strtoupper( $value ),
);
}
}
26 changes: 26 additions & 0 deletions src/Models/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;


/**
Expand Down Expand Up @@ -177,6 +178,17 @@ public function latest() : MorphOne
}


/**
* Generate a new unique key for the model.
*
* @return string
*/
public function newUniqueId()
{
return strtoupper( (string) Str::uuid7() );
}


/**
* Publish the given version of the element.
*
Expand Down Expand Up @@ -273,6 +285,20 @@ protected function data(): Attribute
}


/**
* Interact with the "id" property.
*
* @return Attribute Eloquent attribute for the "id" property
*/
protected function id(): Attribute
{
return Attribute::make(
get: fn( $value ) => strtoupper( $value ),
set: fn( $value ) => strtoupper( $value ),
);
}


/**
* Prepare the model for pruning.
*/
Expand Down
26 changes: 26 additions & 0 deletions src/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
use Intervention\Image\ImageManager;

Expand Down Expand Up @@ -267,6 +268,17 @@ public function latest() : MorphOne
}


/**
* Generate a new unique key for the model.
*
* @return string
*/
public function newUniqueId()
{
return strtoupper( (string) Str::uuid7() );
}


/**
* Get the prunable model query.
*
Expand Down Expand Up @@ -491,6 +503,20 @@ protected function filename( string $filename, ?string $ext = null, array $size
}


/**
* Interact with the "id" property.
*
* @return Attribute Eloquent attribute for the "id" property
*/
protected function id(): Attribute
{
return Attribute::make(
get: fn( $value ) => strtoupper( $value ),
set: fn( $value ) => strtoupper( $value ),
);
}


/**
* Prepare the model for pruning.
*/
Expand Down
26 changes: 26 additions & 0 deletions src/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;


/**
Expand Down Expand Up @@ -336,6 +337,17 @@ public function nav( $level = 0 ) : \Aimeos\Nestedset\Collection
}


/**
* Generate a new unique key for the model.
*
* @return string
*/
public function newUniqueId()
{
return strtoupper( (string) Str::uuid7() );
}


/**
* Relation to the parent.
*
Expand Down Expand Up @@ -513,6 +525,20 @@ protected function domain(): Attribute
}


/**
* Interact with the "id" property.
*
* @return Attribute Eloquent attribute for the "id" property
*/
protected function id(): Attribute
{
return Attribute::make(
get: fn( $value ) => strtoupper( $value ),
set: fn( $value ) => strtoupper( $value ),
);
}


/**
* Interact with the "name" property.
*
Expand Down
33 changes: 32 additions & 1 deletion src/Models/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
namespace Aimeos\Cms\Models;

use Aimeos\Cms\Concerns\Tenancy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;


/**
Expand Down Expand Up @@ -49,9 +51,13 @@ class Version extends Model
protected $casts = [
'data' => 'object',
'aux' => 'object',
'created_at' => 'datetime:Y-m-d H:i:s',
];

/**
* The date format with milliseconds used by created_at.
*/
protected $dateFormat = 'Y-m-d H:i:s.v';

/**
* The attributes that are mass assignable.
*
Expand Down Expand Up @@ -145,6 +151,17 @@ public function getUpdatedAtColumn()
}


/**
* Generate a new unique key for the model.
*
* @return string
*/
public function newUniqueId()
{
return strtoupper( (string) Str::uuid7() );
}


/**
* Get the parent versionable model (page, file or element).
*/
Expand Down Expand Up @@ -183,4 +200,18 @@ public function getDirty()

return $dirty;
}


/**
* Interact with the "id" property.
*
* @return Attribute Eloquent attribute for the "id" property
*/
protected function id(): Attribute
{
return Attribute::make(
get: fn( $value ) => strtoupper( $value ),
set: fn( $value ) => strtoupper( $value ),
);
}
}
6 changes: 4 additions & 2 deletions tests/GraphqlElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function testElementVersions()

$this->expectsDatabaseQueryCount(3);

\Illuminate\Support\Facades\DB::enableQueryLog();
$response = $this->actingAs($this->user)->graphQL('{
element(id: "' . $element->id . '") {
id
Expand All @@ -237,6 +238,8 @@ public function testElementVersions()
}
}
}');
print_r(\Illuminate\Support\Facades\DB::getQueryLog());
print_r(\Illuminate\Support\Facades\DB::table('cms_versions')->get()->all());

$elementData = $response->json('data.element');

Expand All @@ -259,9 +262,8 @@ public function testAddElement()
$this->seed(CmsSeeder::class);

$file = File::where( 'mime', 'image/jpeg' )->firstOrFail();
$element = Element::where( 'type', 'footer' )->firstOrFail();

$this->expectsDatabaseQueryCount( 8 );
$this->expectsDatabaseQueryCount( 7 );

$response = $this->actingAs($this->user)->graphQL('
mutation {
Expand Down
2 changes: 1 addition & 1 deletion tests/GraphqlFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function testAddFile()
{
$this->seed( CmsSeeder::class );

$this->expectsDatabaseQueryCount( 4 );
$this->expectsDatabaseQueryCount( 3 );
$response = $this->actingAs( $this->user )->multipartGraphQL( [
'query' => '
mutation($file: Upload!, $preview: Upload) {
Expand Down
6 changes: 3 additions & 3 deletions tests/GraphqlPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public function testAddPage()
$file = File::where( 'mime', 'image/jpeg' )->firstOrFail();
$element = Element::where( 'type', 'footer' )->firstOrFail();

$this->expectsDatabaseQueryCount( 10 );
$this->expectsDatabaseQueryCount( 9 );
$response = $this->actingAs( $this->user )->graphQL( '
mutation {
addPage(input: {
Expand Down Expand Up @@ -641,7 +641,7 @@ public function testAddPageChild()

$root = Page::where('tag', 'root')->firstOrFail();

$this->expectsDatabaseQueryCount( 10 );
$this->expectsDatabaseQueryCount( 8 );
$response = $this->actingAs( $this->user )->graphQL( '
mutation {
addPage(input: {
Expand Down Expand Up @@ -681,7 +681,7 @@ public function testAddPageChildRef()
$root = Page::where('tag', 'root')->firstOrFail();
$ref = Page::where('tag', 'blog')->firstOrFail();

$this->expectsDatabaseQueryCount( 10 );
$this->expectsDatabaseQueryCount( 8 );
$response = $this->actingAs( $this->user )->graphQL( '
mutation {
addPage(input: {
Expand Down