Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e0be718
wip
riasvdv Nov 6, 2025
23ef579
QueriesStatuses
riasvdv Nov 6, 2025
1a5628c
Lots of refactoring
riasvdv Nov 6, 2025
b9bf365
wip
riasvdv Nov 9, 2025
8f70bd7
Move QueryParam
riasvdv Nov 10, 2025
97e944d
Add tests for Query
riasvdv Nov 10, 2025
59c11de
date queries
riasvdv Nov 10, 2025
82af619
Tests for QueriesFields
riasvdv Nov 10, 2025
66902ef
Refactor a bit
riasvdv Nov 10, 2025
6dd6b14
Hydrate elements
riasvdv Nov 10, 2025
da375aa
Extra test
riasvdv Nov 10, 2025
952fb7d
Add docblocks + cleanup
riasvdv Nov 10, 2025
087aeec
Initial test for search
riasvdv Nov 10, 2025
b252993
More refactoring + get search in a working state
riasvdv Nov 11, 2025
06ea60f
More search
riasvdv Nov 11, 2025
e6cdb76
Add some more tests
riasvdv Nov 11, 2025
83fd017
Tests for drafts & custom fields
riasvdv Nov 12, 2025
a5fdc4c
Tests for revisions
riasvdv Nov 12, 2025
f31faa7
Replace queryCondition with modifyQuery on fields
riasvdv Nov 12, 2025
af3fd0a
Eagerly
riasvdv Nov 13, 2025
9a34076
Fix count
riasvdv Nov 13, 2025
3ef2fbb
Tests for QueriesSections
riasvdv Nov 13, 2025
5038f41
Move logic in beforeQuery
riasvdv Nov 13, 2025
d7103ba
QueriesEntryTypes
riasvdv Nov 13, 2025
88237db
Fix columns not being able to load
riasvdv Nov 13, 2025
5350964
Add QueriesAuthors, QueriesEntryDates & QueriesNestedElements
riasvdv Nov 13, 2025
06a43f6
Merge branch '6.x' into feature/entry-query
riasvdv Nov 14, 2025
3d63bd0
Merge branch '6.x' into feature/entry-query
riasvdv Nov 15, 2025
9d9a1bc
Test for QueriesSites
riasvdv Nov 17, 2025
9e7559e
Test for QueriesAuthors
riasvdv Nov 17, 2025
e0af913
Add test for QueriesEntryDates
riasvdv Nov 17, 2025
211057f
QueriesUniqueElementsTest + pgsql fixes
riasvdv Nov 17, 2025
d87187e
Tests for QueriesStructures
riasvdv Nov 17, 2025
d6eedb6
Fix a few phpstan errors
riasvdv Nov 18, 2025
7e3cbdf
Test for QueriesNestedElements
riasvdv Nov 18, 2025
842eeed
Test for QueriesPlaceholders
riasvdv Nov 18, 2025
f261fb2
Replace ElementRelationParamParser and add test for QueriesRelatedEle…
riasvdv Nov 18, 2025
fb2f0f3
Avoid extra groups when there is only 1 param
riasvdv Nov 18, 2025
24366f2
Add more tests for EntryQuery
riasvdv Nov 18, 2025
f7341cd
Fix phpstan errors
riasvdv Nov 18, 2025
b603d2c
CachesQueries
riasvdv Nov 19, 2025
6ce3533
Add method to key
riasvdv Nov 19, 2025
c38326b
Refactor
riasvdv Nov 19, 2025
44d7c04
Result overrides
riasvdv Nov 19, 2025
49b9e15
phpstan
riasvdv Nov 19, 2025
a05e7bd
phpstan fixes
riasvdv Nov 19, 2025
4ce5426
Test fixes
riasvdv Nov 19, 2025
50592a5
Fix typehint
riasvdv Nov 19, 2025
e83a3b7
Fix some legacy tests
riasvdv Nov 19, 2025
c7255c0
Old element type for now (ResaveElements Job is not ported yet)
riasvdv Nov 19, 2025
abe5b9e
Fix calls to getCachedResult
riasvdv Nov 19, 2025
96705b6
Merge branch '6.x' into feature/entry-query
riasvdv Nov 20, 2025
550037d
Add macros for deprecated/renamed functions
riasvdv Nov 20, 2025
5fd967c
Legacy can use collect() for now
riasvdv Nov 20, 2025
245ccdd
Move Entry specific concerns to Entry folder
riasvdv Nov 20, 2025
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
43 changes: 43 additions & 0 deletions database/Factories/DraftFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace CraftCms\Cms\Database\Factories;

use craft\elements\Entry;
use CraftCms\Cms\Element\Models\Draft;
use CraftCms\Cms\Element\Models\Element;
use CraftCms\Cms\User\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

final class DraftFactory extends Factory
{
protected $model = Draft::class;

#[\Override]
public function definition(): array
{
return [
'canonicalId' => Element::factory(),
'creatorId' => User::factory(),
'provisional' => fake()->boolean(),
'name' => fake()->words(asText: true),
'trackChanges' => fake()->boolean(),
'dateLastMerged' => now(),
'saved' => fake()->boolean(),
];
}

#[\Override]
public function configure(): self
{
return $this->afterCreating(function (Draft $draft) {
$element = Element::create([
'type' => Entry::class,
'canonicalId' => $draft->canonicalId,
]);

$draft->update(['id' => $element->id]);
});
}
}
8 changes: 6 additions & 2 deletions database/Factories/ElementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use CraftCms\Cms\Support\Str;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\DB;
use Override;

final class ElementFactory extends Factory
{
protected $model = Element::class;

#[\Override]
#[Override]
public function definition(): array
{
return [
Expand All @@ -27,13 +28,16 @@ public function definition(): array
];
}

#[\Override]
#[Override]
public function configure(): self
{
return $this->afterCreating(function (Element $element) {
DB::table(Table::ELEMENTS_SITES)
->insert([
'elementId' => $element->id,
'title' => fake()->words(asText: true),
'slug' => fake()->slug(),
'uri' => fake()->slug(),
'enabled' => true,
'siteId' => Site::first()->id,
'dateCreated' => $element->dateCreated,
Expand Down
62 changes: 61 additions & 1 deletion database/Factories/EntryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
use CraftCms\Cms\Entry\Models\EntryType;
use CraftCms\Cms\Section\Models\Section;
use Illuminate\Database\Eloquent\Factories\Factory;
use Override;

final class EntryFactory extends Factory
{
protected $model = Entry::class;

#[\Override]
#[Override]
public function definition(): array
{
return [
Expand All @@ -27,4 +28,63 @@ public function definition(): array
'dateUpdated' => $created,
];
}

#[Override]
public function configure(): self
{
$this->afterCreating(function (Entry $entry) {
$entry->element->update([
'dateCreated' => $entry->postDate,
'dateUpdated' => $entry->postDate,
]);
});

return $this;
}

public function trashed(bool $trashed = true): self
{
return $this->state(fn (array $attributes) => [
'id' => $attributes['id']->trashed($trashed),
]);
}

public function archived(bool $archived = true): self
{
return $this->state(fn (array $attributes) => [
'id' => $attributes['id']->set('archived', $archived),
]);
}

public function enabled(bool $enabled = true): self
{
return $this->state(fn (array $attributes) => [
'id' => $attributes['id']->set('enabled', $enabled),
]);
}

public function disabled(bool $disabled = true): self
{
return $this->state(fn (array $attributes) => [
'id' => $attributes['id']->set('enabled', ! $disabled),
]);
}

public function pending(bool $pending = true): self
{
return $this->state(fn (array $attributes) => [
'postDate' => $pending
? fake()->dateTimeBetween('+1 day', '+1 year')
: fake()->dateTime(),
]);
}

public function expired(bool $expired = true): self
{
return $this->state(fn (array $attributes) => [
'expiryDate' => $expired
? fake()->dateTime()
: fake()->dateTimeBetween('+1 day', '+1 year'),
]);
}
}
26 changes: 26 additions & 0 deletions database/Factories/UserGroupFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace CraftCms\Cms\Database\Factories;

use CraftCms\Cms\User\Models\UserGroup;
use Illuminate\Database\Eloquent\Factories\Factory;
use Override;

final class UserGroupFactory extends Factory
{
protected $model = UserGroup::class;

#[Override]
public function definition(): array
{
return [
'name' => fake()->words(asText: true),
'handle' => fake()->slug(),
'description' => fake()->paragraph(),
'dateCreated' => $date = fake()->dateTime(),
'dateUpdated' => $date,
];
}
}
27 changes: 14 additions & 13 deletions src/Dashboard/Widgets/MyDrafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace CraftCms\Cms\Dashboard\Widgets;

use Craft;
use craft\elements\Entry;
use craft\helpers\Cp;
use CraftCms\Cms\Element\Elements\Entry;
use CraftCms\Cms\Support\Html;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Override;

use function CraftCms\Cms\t;

Expand All @@ -17,7 +18,7 @@ final class MyDrafts extends Widget
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function displayName(): string
{
return t('My Drafts');
Expand All @@ -26,7 +27,7 @@ public static function displayName(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
protected static function allowMultipleInstances(): bool
{
return false;
Expand All @@ -40,13 +41,13 @@ protected static function allowMultipleInstances(): bool
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function icon(): string
{
return 'scribble';
}

#[\Override]
#[Override]
public static function getRules(): array
{
return [
Expand All @@ -57,7 +58,7 @@ public static function getRules(): array
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getSettingsHtml(): string
{
return Cp::textFieldHtml([
Expand All @@ -73,22 +74,22 @@ public function getSettingsHtml(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getBodyHtml(): string
{
/** @var Entry[] $drafts */
/** @var \craft\elements\ElementCollection<Entry> $drafts */
$drafts = Entry::find()
->drafts()
->status(null)
->draftCreator(Craft::$app->getUser()->getId())
->draftCreator(Auth::user()->id)
->section('*')
->site('*')
->unique()
->orderBy(['dateUpdated' => SORT_DESC])
->orderByDesc('dateUpdated')
->limit($this->limit)
->all();
->get();

if (empty($drafts)) {
if ($drafts->isEmpty()) {
return Html::tag('div', t('You don’t have any active drafts.'), [
'class' => ['zilch', 'small'],
]);
Expand Down
33 changes: 16 additions & 17 deletions src/Dashboard/Widgets/RecentEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace CraftCms\Cms\Dashboard\Widgets;

use Craft;
use craft\elements\Entry;
use craft\models\Section;
use craft\elements\ElementCollection;
use craft\web\assets\recententries\RecentEntriesAsset;
use CraftCms\Cms\Element\Elements\Entry;
use CraftCms\Cms\Section\Enums\SectionType;
use CraftCms\Cms\Support\Facades\Sections;
use CraftCms\Cms\Support\Facades\Sites;
use CraftCms\Cms\Support\Json;
use Override;

use function CraftCms\Cms\t;

Expand All @@ -20,7 +21,7 @@ final class RecentEntries extends Widget
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function displayName(): string
{
return t('Recent Entries');
Expand All @@ -29,7 +30,7 @@ public static function displayName(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function icon(): string
{
return 'clock';
Expand Down Expand Up @@ -57,7 +58,7 @@ public function __construct(array $config = [])
$this->siteId ??= Sites::getCurrentSite()->id;
}

#[\Override]
#[Override]
public static function getRules(): array
{
return [
Expand All @@ -69,7 +70,7 @@ public static function getRules(): array
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getSettingsHtml(): string
{
return Craft::$app->getView()->renderTemplate('_components/widgets/RecentEntries/settings.twig',
Expand All @@ -81,7 +82,7 @@ public function getSettingsHtml(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getTitle(): string
{
if (is_numeric($this->section) && $section = Sections::getSectionById((int) $this->section)) {
Expand All @@ -98,7 +99,7 @@ public function getTitle(): string
// See if they are pulling entries from a different site
$targetSiteId = $this->getTargetSiteId();

if ($targetSiteId !== null && $targetSiteId != Sites::getCurrentSite()->id) {
if ($targetSiteId !== null && $targetSiteId !== Sites::getCurrentSite()->id) {
$site = Sites::getSiteById($targetSiteId);

if ($site) {
Expand All @@ -115,7 +116,7 @@ public function getTitle(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getBodyHtml(): string
{
$params = [];
Expand All @@ -134,22 +135,20 @@ public function getBodyHtml(): string

return $view->renderTemplate('_components/widgets/RecentEntries/body.twig',
[
'entries' => $entries,
'entries' => $entries->all(),
]);
}

/**
* Returns the recent entries, based on the widget settings and user permissions.
*
* @return Entry[]
*/
private function getEntries(): array
private function getEntries(): ElementCollection
{
$targetSiteId = $this->getTargetSiteId();

if ($targetSiteId === null) {
// Hopeless
return [];
return new ElementCollection;
}

// Normalize the target section ID value.
Expand All @@ -161,7 +160,7 @@ private function getEntries(): array
}

if (! $targetSectionId) {
return [];
return new ElementCollection;
}

return Entry::find()
Expand All @@ -171,8 +170,8 @@ private function getEntries(): array
->siteId($targetSiteId)
->limit($this->limit ?: 100)
->with(['author'])
->orderBy(['dateCreated' => SORT_DESC])
->all();
->orderByDesc('dateCreated')
->get();
}

/**
Expand Down
Loading
Loading