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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"commerceguys/addressing": "^2.1.1",
"composer/semver": "^3.3.2",
"craftcms/laravel-aliases": "^2.0",
"craftcms/laravel-dependency-aware-cache": "^1.0",
"craftcms/laravel-dependency-aware-cache": "^1.1",
"craftcms/plugin-installer": "~1.6.0",
"craftcms/server-check": "~5.0.1",
"craftcms/yii2-adapter": "self.version",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Console/Commands/Utils/AsciiFilenamesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace CraftCms\Cms\Console\Commands\Utils;

use Craft;
use craft\errors\InvalidElementException;
use craft\helpers\FileHelper;
use CraftCms\Cms\Asset\Elements\Asset;
use CraftCms\Cms\Config\GeneralConfig;
use CraftCms\Cms\Console\CraftCommand;
use CraftCms\Cms\Element\Exceptions\InvalidElementException;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
Expand Down
4 changes: 1 addition & 3 deletions src/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ public function changeWidgetColspan(int $widgetId, int $colspan): bool
*/
private function addDefaultUserWidgets(): void
{
/** @var ?\craft\elements\User $user */
$user = Auth::user();

// Recent Entries widget
Expand Down Expand Up @@ -330,7 +329,7 @@ private function addDefaultUserWidgets(): void

private function getUserWidgetModelById(?int $widgetId = null): Models\Widget
{
$userId = Auth::user()->getAuthIdentifier();
$userId = Auth::user()?->getAuthIdentifier();

if ($widgetId !== null) {
return Models\Widget::query()
Expand All @@ -354,7 +353,6 @@ private function getUserWidgetModelById(?int $widgetId = null): Models\Widget
*/
private function getUserWidgets(): Collection|false
{
/** @var User $user */
$user = Auth::user();

if (! $user) {
Expand Down
19 changes: 10 additions & 9 deletions src/Dashboard/Widgets/CraftSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use CraftCms\Cms\Plugin\Plugins;
use CraftCms\Cms\Support\PHP;
use Illuminate\Support\Facades\Auth;
use Override;

use function CraftCms\Cms\normalizeVersion;
use function CraftCms\Cms\t;
Expand All @@ -29,7 +30,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function displayName(): string
{
return t('Craft Support');
Expand All @@ -38,17 +39,17 @@ public static function displayName(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function isSelectable(): bool
{
// Only admins get the Craft Support widget.
return parent::isSelectable() && Auth::user()->isAdmin();
return parent::isSelectable() && Auth::user()?->isAdmin();
}

/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
protected static function allowMultipleInstances(): bool
{
return false;
Expand All @@ -57,7 +58,7 @@ protected static function allowMultipleInstances(): bool
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public static function icon(): string
{
return 'life-ring';
Expand All @@ -66,7 +67,7 @@ public static function icon(): string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getTitle(): ?string
{
return null;
Expand All @@ -75,11 +76,11 @@ public function getTitle(): ?string
/**
* {@inheritdoc}
*/
#[\Override]
#[Override]
public function getBodyHtml(): ?string
{
// Only admins get the Craft Support widget.
if (! Auth::user()->isAdmin()) {
if (! Auth::user()?->isAdmin()) {
return null;
}

Expand Down Expand Up @@ -126,7 +127,7 @@ public function getBodyHtml(): ?string
EOD;

$view->registerJsWithVars(fn ($id, $settings) => <<<JS
new Craft.CraftSupportWidget($id, $settings);
new Craft.CraftSupportWidget($id, $settings)
JS, [
$this->id,
[
Expand Down
2 changes: 1 addition & 1 deletion src/Dashboard/Widgets/NewUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace CraftCms\Cms\Dashboard\Widgets;

use Craft;
use craft\elements\User;
use craft\web\assets\newusers\NewUsersAsset;
use CraftCms\Cms\Edition;
use CraftCms\Cms\Support\Facades\I18N;
use CraftCms\Cms\Support\Facades\UserGroups;
use CraftCms\Cms\Support\Json;
use CraftCms\Cms\User\Elements\User;
use Override;

use function CraftCms\Cms\t;
Expand Down
5 changes: 3 additions & 2 deletions src/Database/Migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Craft;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\elements\User;
use craft\helpers\DateTimeHelper;
use craft\mail\transportadapters\Sendmail;
use craft\web\Response;
Expand All @@ -31,7 +30,9 @@
use CraftCms\Cms\Shared\Models\Info;
use CraftCms\Cms\Site\Data\Site;
use CraftCms\Cms\Support\Facades\Sites;
use CraftCms\Cms\Support\Facades\Users;
use CraftCms\Cms\Support\Str;
use CraftCms\Cms\User\Elements\User;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -1128,7 +1129,7 @@ public function insertDefaultData(): void
]);
Craft::$app->getElements()->saveElement($user);

Craft::$app->getUsers()->saveUserPreferences($user, [
Users::saveUserPreferences($user, [
'language' => $this->site->getLanguage(),
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Queries/AssetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function applyAuthParam(?bool $value, string $permissionPrefix, string $
});
}

protected function createElement(array $row): ElementInterface
public function createElement(array $row): ElementInterface
{
// Use the site-specific alt text, if set
$siteAlt = Arr::pull($row, 'siteAlt');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace CraftCms\Cms\Database\Queries\Concerns\Asset;

use craft\elements\User;
use craft\helpers\Assets;
use CraftCms\Cms\Database\Queries\AssetQuery;
use CraftCms\Cms\Support\Arr;
use CraftCms\Cms\User\Elements\User;
use CraftCms\Cms\User\Models\User as UserModel;
use Illuminate\Database\Query\Builder;
use yii\base\InvalidArgumentException;
Expand Down
11 changes: 10 additions & 1 deletion src/Database/Queries/Concerns/HydratesElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use CraftCms\Cms\Database\Queries\Events\HydratingElement;
use CraftCms\Cms\Support\Arr;
use CraftCms\Cms\Support\Json;
use CraftCms\Cms\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use stdClass;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function hydrate(array $items): array
return $elements;
}

protected function createElement(array $row): ElementInterface
public function createElement(array $row): ElementInterface
{
// Do we have a placeholder for this element?
if (
Expand Down Expand Up @@ -197,6 +198,14 @@ protected function createElement(array $row): ElementInterface
}
}

/**
* When using addSelect() to select extra columns, they might appear
* as `table.column`. We just want `column`
*/
$row = collect($row)
->mapWithKeys(fn (mixed $value, string $key) => [Str::after($key, '.') => $value])
->all();

$element ??= new $class($row);

if (Event::hasListeners(ElementHydrated::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait QueriesAssetUploaders
* ---
* ```php
* // fetch all users who have uploaded an asset
* $uploaders = \craft\elements\User::find()
* $uploaders = \CraftCms\Cms\User\Elements\User::find()
* ->assetUploaders()
* ->all();
* ```
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Queries/Concerns/User/QueriesAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait QueriesAuthors
* ---
* ```php
* // fetch all authors
* $authors = \craft\elements\User::find()
* $authors = \CraftCms\Cms\User\Elements\User::find()
* ->authors()
* ->all();
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ trait QueriesRolesAndPermissions
* ---
* ```php
* // fetch all the admins
* $admins = \craft\elements\User::find()
* $admins = \CraftCms\Cms\User\Elements\User::find()
* ->admin(true)
* ->all();
*
* // fetch all the non-admins
* $nonAdmins = \craft\elements\User::find()
* $nonAdmins = \CraftCms\Cms\User\Elements\User::find()
* ->admin(false)
* ->all();
* ```
Expand All @@ -51,7 +51,7 @@ trait QueriesRolesAndPermissions
* ---
* ```php
* // fetch users who can access the front end when the system is offline
* $admins = \craft\elements\User::find()
* $admins = \CraftCms\Cms\User\Elements\User::find()
* ->can('accessSiteWhenSystemIsOff')
* ->all();
* ```
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Queries/Concerns/User/QueriesUserGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait QueriesUserGroups
* ---
* ```php
* // fetch the authors
* $admins = \craft\elements\User::find()
* $admins = \CraftCms\Cms\User\Elements\User::find()
* ->group('authors')
* ->all();
* ```
Expand All @@ -45,7 +45,7 @@ trait QueriesUserGroups
* ---
* ```php
* // fetch users with their user groups
* $users = \craft\elements\User::find()
* $users = \CraftCms\Cms\User\Elements\User::find()
* ->withGroups()
* ->all();
* ```
Expand Down Expand Up @@ -239,7 +239,7 @@ public function groupId(mixed $value): self
*
* ```php
* // fetch users with their user groups
* $users = \craft\elements\User::find()
* $users = \CraftCms\Cms\User\Elements\User::find()
* ->withGroups()
* ->all();
* ```
Expand Down
28 changes: 19 additions & 9 deletions src/Database/Queries/ElementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
*
* @mixin \Illuminate\Database\Query\Builder
*
* @method self addSelect($column)
* @method self orderByDesc($column)
* @method self where($column, $operator = null, $value = null, $boolean = 'and')
* @method self whereIn($column, $values, $boolean = 'and', $not = false)
* @method self whereNot($column, $operator = null, $value = null, $boolean = 'and')
* @method self whereNotIn($column, $values, $boolean = 'and')
* @method self whereNotNull($columns, $boolean = 'and')
* @method self whereNotExists($callback, $boolean = 'and')
* @method static addSelect($column)
* @method static orderByDesc($column)
* @method static where($column, $operator = null, $value = null, $boolean = 'and')
* @method static whereIn($column, $values, $boolean = 'and', $not = false)
* @method static whereNot($column, $operator = null, $value = null, $boolean = 'and')
* @method static whereNotIn($column, $values, $boolean = 'and')
* @method static whereNotNull($columns, $boolean = 'and')
* @method static whereNotExists($callback, $boolean = 'and')
*/
class ElementQuery implements \Illuminate\Contracts\Database\Query\Builder
{
Expand Down Expand Up @@ -832,7 +832,17 @@ public function __call($method, $parameters): mixed
return $this->getQuery()->{$method}(...$parameters);
}

if (in_array(strtolower($method), ['orderby', 'orderbydesc', 'select', 'reorder'])) {
/**
* Joins should be done on both queries
*/
if (str_contains(strtolower($method), 'join')) {
$this->forwardCallTo($this->query, $method, $parameters);
$this->forwardCallTo($this->subQuery, $method, $parameters);

return $this;
}

if (in_array(strtolower($method), ['orderby', 'orderbydesc', 'select', 'reorder', 'addselect'])) {
$this->forwardCallTo($this->query, $method, $parameters);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Element/Concerns/Draftable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace CraftCms\Cms\Element\Concerns;

use Craft;
use craft\elements\User as UserElement;
use CraftCms\Cms\Database\Table;
use CraftCms\Cms\Element\Events\AuthorizeCreateDrafts;
use CraftCms\Cms\User\Elements\User as UserElement;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;

Expand Down
2 changes: 1 addition & 1 deletion src/Element/Concerns/Revisionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use craft\base\ElementInterface;
use craft\elements\db\ElementQuery;
use craft\elements\User;
use craft\helpers\UrlHelper;
use CraftCms\Cms\Database\Table;
use CraftCms\Cms\Support\Facades\Sites;
use CraftCms\Cms\User\Elements\User;
use Illuminate\Support\Facades\DB;

use function CraftCms\Cms\t;
Expand Down
Loading
Loading