Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mooxphp/moox
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-the-Diamond committed Sep 6, 2024
2 parents d80f493 + ee45cd2 commit 2a113e3
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions packages/press/src/Resources/WpUserResource/Pages/EditWpUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Moox\Press\Models\WpBasePost;
use Moox\Press\Models\WpPostMeta;
use Moox\Press\Models\WpUser;
use Moox\Press\Models\WpUserMeta;
use Moox\Press\Resources\WpUserResource;
use Symfony\Component\Mime\MimeTypes;

Expand Down Expand Up @@ -58,6 +57,13 @@ protected function afterSave(): void

$user->save();

$metaFields = config('press.default_user_meta', []);
foreach ($metaFields as $metaKey => $defaultValue) {
if (isset($this->data[$metaKey])) {
$user->addOrUpdateMeta($metaKey, $this->data[$metaKey]);

Check failure on line 63 in packages/press/src/Resources/WpUserResource/Pages/EditWpUser.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method addOrUpdateMeta() on Illuminate\Database\Eloquent\Model|int|string.
}
}

$temporaryFilePath = $this->data['temporary_file_path'] ?? null;
$originalName = $this->data['original_name'] ?? null;
$attachmentId = null;
Expand Down Expand Up @@ -138,33 +144,6 @@ protected function afterSave(): void
Storage::delete($temporaryFilePath);
}

$metaDataConfig = config('press.default_user_meta');

foreach ($metaDataConfig as $metaKey => $defaultValue) {
$metaValue = $this->data[$metaKey] ?? $defaultValue;

if ($metaKey === 'nickname') {
$metaValue = $this->data['user_login'];
}

if ($metaKey === 'mm_sua_attachment_id') {
if ($temporaryFilePath) {
$metaValue = $attachmentId;
} elseif (empty($this->data['image_url'])) {
$metaValue = '';
}
}

if ($this->record instanceof WpUser) {
$userId = $this->record->ID;

WpUserMeta::updateOrCreate(
['user_id' => $userId, 'meta_key' => $metaKey],
['meta_value' => $metaValue]
);
}
}

Event::dispatch('eloquent.updated: '.get_class($this->record), $this->record);
}
}

0 comments on commit 2a113e3

Please sign in to comment.