/**
* Attempt to authenticate a user using the given credentials.
*
- * @param array $credentials
* @param bool $remember
*
- * @throws LdapException*@throws \BookStack\Exceptions\JsonDebugException
+ * @throws LdapException
* @throws LoginAttemptException
* @throws JsonDebugException
- *
- * @return bool
*/
- public function attempt(array $credentials = [], $remember = false)
+ public function attempt(array $credentials = [], $remember = false): bool
{
$username = $credentials['username'];
$userDetails = $this->ldapService->getUserDetails($username);
use BookStack\Permissions\PermissionApplicator;
use BookStack\Users\Models\User;
use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\Relation;
class ActivityQueries
$activity = $query->orderBy('created_at', 'desc')
->with(['loggable' => function (Relation $query) {
+ /** @var MorphTo<Entity, Activity> $query */
$query->withTrashed();
}, 'user.avatar'])
->skip($count * ($page - 1))
throw new \InvalidArgumentException("Detail for page update notifications must be a page");
}
- // Get last update from activity
+ // Get the last update from activity
+ /** @var ?Activity $lastUpdate */
$lastUpdate = $detail->activity()
->where('type', '=', ActivityType::PAGE_UPDATE)
->where('id', '!=', $activity->id)
}
if ($this->detail instanceof Model) {
- $data['related_item'] = $this->formatModel();
+ $data['related_item'] = $this->formatModel($this->detail);
}
return $data;
);
}
- protected function formatModel(): array
+ protected function formatModel(Model $model): array
{
- /** @var Model $model */
- $model = $this->detail;
$model->unsetRelations();
foreach ($this->modelFormatters as $formatter) {
namespace BookStack\Entities\Controllers;
+use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Queries\ChapterQueries;
use BookStack\Entities\Queries\EntityQueries;
$chapter->load(['tags']);
$chapter->makeVisible('description_html');
$chapter->setAttribute('description_html', $chapter->descriptionHtml());
- $chapter->setAttribute('book_slug', $chapter->book()->first()->slug);
+
+ /** @var Book $book */
+ $book = $chapter->book()->first();
+ $chapter->setAttribute('book_slug', $book->slug);
return $chapter;
}
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
public function getParent(): ?self
{
if ($this instanceof Page) {
- return $this->chapter_id ? $this->chapter()->withTrashed()->first() : $this->book()->withTrashed()->first();
+ /** @var BelongsTo<Chapter|Book, Page> $builder */
+ $builder = $this->chapter_id ? $this->chapter() : $this->book();
+ return $builder->withTrashed()->first();
}
if ($this instanceof Chapter) {
- return $this->book()->withTrashed()->first();
+ /** @var BelongsTo<Book, Page> $builder */
+ $builder = $this->book();
+ return $builder->withTrashed()->first();
}
return null;
/**
* Rebuild the permissions for this entity.
*/
- public function rebuildPermissions()
+ public function rebuildPermissions(): void
{
app()->make(JointPermissionBuilder::class)->rebuildForEntity(clone $this);
}
/**
* Index the current entity for search.
*/
- public function indexForSearch()
+ public function indexForSearch(): void
{
app()->make(SearchIndex::class)->indexEntity(clone $this);
}
// Find and include images if in visibility
$page = $model->getPage();
- if ($page && userCan('view', $page)) {
+ if ($page && userCan('view', $page) && $exportModel instanceof ZipExportPage) {
if (!isset($this->images[$model->id])) {
$exportImage = ZipExportImage::fromModel($model, $files);
$this->images[$model->id] = $exportImage;
/**
* @property int $created_by
* @property int $updated_by
+ * @property ?User $createdBy
+ * @property ?User $updatedBy
*/
trait HasCreatorAndUpdater
{