diff --git a/app/Http/Controllers/CampaignBoostController.php b/app/Http/Controllers/CampaignBoostController.php index 2c925f909f..438b6516b5 100644 --- a/app/Http/Controllers/CampaignBoostController.php +++ b/app/Http/Controllers/CampaignBoostController.php @@ -172,7 +172,6 @@ public function confirm(CampaignBoost $campaignBoost) } /** - * @return \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function destroy(CampaignBoost $campaignBoost) diff --git a/app/Models/Entity.php b/app/Models/Entity.php index a7501ed8c7..df850ebb0a 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -196,6 +196,7 @@ public function mappedPreview(): string if (!$this->child->hasEntry()) { return ''; } + // @phpstan-ignore-next-line return Str::limit(strip_tags($this->child->parsedEntry()), 500); } diff --git a/app/Models/MiscModel.php b/app/Models/MiscModel.php index 8ee21e6321..149aef8d80 100644 --- a/app/Models/MiscModel.php +++ b/app/Models/MiscModel.php @@ -26,6 +26,7 @@ * @property int $id * Still keep campaign_id for phpstan * @property int $campaign_id + * @property string $entry * @property string $name * @property string $type * @property string $slug diff --git a/app/Observers/EntryObserver.php b/app/Observers/EntryObserver.php index b16f09b23d..a8bbe327df 100644 --- a/app/Observers/EntryObserver.php +++ b/app/Observers/EntryObserver.php @@ -23,14 +23,17 @@ public function saving(Model $model) // When creating modules through the API, there might be no entry, which is why we need to // check if they are in the attributes of the model before interacting with it; $attributes = $model->getAttributes(); + // @phpstan-ignore-next-line if (!array_key_exists($model->entryFieldName(), $attributes)) { return; } + // @phpstan-ignore-next-line $model->{$model->entryFieldName()} = $this->purify(Mentions::codify($model->{$model->entryFieldName()})); } public function saved(Model $model) { + // @phpstan-ignore-next-line if ($model->isDirty($model->entryFieldName())) { if ($model instanceof MiscModel) { $this->entityMappingService->with($model->entity); diff --git a/app/Services/AttributeService.php b/app/Services/AttributeService.php index 17a20e0e59..e2e766ed53 100644 --- a/app/Services/AttributeService.php +++ b/app/Services/AttributeService.php @@ -303,8 +303,10 @@ public function replaceMentions(int $sourceId): self $searchAttributes[] = '{attribute:' . $sourceAttributes[$slug] . '}'; $replaceAttributes[] = '{attribute:' . $attribute->id . '}'; } - $entry = Str::replace($searchAttributes, $replaceAttributes, $this->entity->child->entry); - $this->entity->child->update(['entry' => $entry]); + if ($this->entity->child->hasEntry()) { + $entry = Str::replace($searchAttributes, $replaceAttributes, $this->entity->child->entry); + $this->entity->child->update(['entry' => $entry]); + } foreach ($this->entity->posts as $post) { $post->entry = Str::replace($searchAttributes, $replaceAttributes, $post->entry); $post->updateQuietly(); diff --git a/app/Services/Campaign/Import/ImportService.php b/app/Services/Campaign/Import/ImportService.php index 5a61051551..be00879ce3 100644 --- a/app/Services/Campaign/Import/ImportService.php +++ b/app/Services/Campaign/Import/ImportService.php @@ -393,7 +393,7 @@ protected function secondCampaign(): self $this->campaign->excerpt = $this->mentions($this->campaign->excerpt); $this->campaign->save(); - $this->entityMappingService->silent()->mapCampaign($this->campaign); + $this->entityMappingService->silent()->with($this->campaign)->map(); return $this; } diff --git a/app/Services/Entity/PostService.php b/app/Services/Entity/PostService.php index 8d31261bc4..80cdc68645 100644 --- a/app/Services/Entity/PostService.php +++ b/app/Services/Entity/PostService.php @@ -46,11 +46,10 @@ public function handle(MovePostRequest $request): Post protected function copy(): Post { $entity = Entity::findOrFail($this->entityId); - /** @var Post $newPost */ $newPost = $this->post->copyTo($entity); // Update the "mentioned in" mapping for the entity - $this->mappingService->mapPost($newPost); + $this->mappingService->with($newPost)->map(); $this->log($newPost, EntityLog::ACTION_CREATE_POST); diff --git a/app/Services/EntityMappingService.php b/app/Services/EntityMappingService.php index 2253a7e299..3998c181d9 100644 --- a/app/Services/EntityMappingService.php +++ b/app/Services/EntityMappingService.php @@ -73,8 +73,8 @@ protected function createNewMention(int $target): void if ($this->model instanceof Campaign) { $mention->campaign_id = $this->model->id; } elseif ($this->model instanceof Post) { - $mention->post_id = $this->model->id; - $mention->entity_id = $this->model->entity_id; + $mention->post_id = $this->post()->id; + $mention->entity_id = $this->post()->entity_id; // If we are making a reference to ourselves, no need to save it if ($this->model->entity_id == $target) { @@ -97,10 +97,11 @@ protected function createNewMention(int $target): void return; } } else { + // @phpstan-ignore-next-line $mention->entity_id = $this->model->id; // If we are making a reference to ourselves, no need to save it - if ($this->model->id == $target) { + if ($this->model->id == $target) { // @phpstan-ignore-line return; } } @@ -118,9 +119,9 @@ protected function images(): self } $images = []; if ($this->model instanceof Entity) { - $images = $this->extractImages($this->model->child->entry); + $images = $this->extractImages($this->entity()->child->entry); } elseif ($this->model instanceof Post) { - $images = $this->extractImages($this->model->entry); + $images = $this->extractImages($this->post()->entry); } $existingTargets = []; if ($this->model instanceof Entity) { @@ -139,9 +140,9 @@ protected function images(): self // Determine the real campaign id from the model. if ($this->model instanceof Post) { - $campaignId = $this->model->entity->campaign_id; + $campaignId = $this->post()->entity->campaign_id; } else { - $campaignId = $this->model->campaign_id; + $campaignId = $this->entity()->campaign_id; } /** @var Image|null $target */ @@ -179,6 +180,7 @@ protected function images(): self protected function entry(): self { $existingTargets = []; + // @phpstan-ignore-next-line foreach ($this->model->mentions as $map) { $existingTargets[$map->target_id] = $map; } @@ -186,8 +188,9 @@ protected function entry(): self $existingMappings = 0; if ($this->model instanceof Entity) { - $mentions = $this->extract($this->model->child->entry); + $mentions = $this->extract($this->entity()->child->entry); } else { + // @phpstan-ignore-next-line $mentions = $this->extract($this->model->{$this->model->entryFieldName()}); } @@ -255,6 +258,7 @@ protected function campaignID(): int } elseif ($this->model instanceof QuestElement) { return $this->model->quest->campaign_id; } + // @phpstan-ignore-next-line return $this->model->campaign_id; } @@ -289,4 +293,15 @@ protected function log(string $message = null) } } } + + protected function post(): Post + { + // @phpstan-ignore-next-line + return $this->model; + } + protected function entity(): Entity + { + // @phpstan-ignore-next-line + return $this->model; + } }