-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add page that allows to fix broken trees * typos * add clarifiations * improve useability * add more checks * Update resources/js/views/FixTree.vue Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com> * Update resources/js/composables/album/treeOperations.ts Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com> --------- Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
- Loading branch information
Showing
21 changed files
with
832 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin\Maintenance; | ||
|
||
use App\Http\Controllers\Admin\Maintenance\Model\Album; | ||
use App\Http\Requests\Maintenance\FullTreeUpdateRequest; | ||
use App\Http\Requests\Maintenance\MaintenanceRequest; | ||
use App\Http\Resources\Diagnostics\AlbumTree; | ||
use Illuminate\Routing\Controller; | ||
use Illuminate\Support\Collection; | ||
|
||
/** | ||
* Maybe the album tree is broken. | ||
* We fix it here. | ||
*/ | ||
class FullTree extends Controller | ||
{ | ||
/** | ||
* Clean the path from all files excluding $this->skip. | ||
* | ||
* @return void | ||
*/ | ||
public function do(FullTreeUpdateRequest $request): void | ||
{ | ||
$keyName = 'id'; | ||
$albumInstance = new Album(); | ||
batch()->update($albumInstance, $request->albums(), $keyName); | ||
} | ||
|
||
/** | ||
* Check whether there are files to be removed. | ||
* If not, we will not display the module to reduce complexity. | ||
* | ||
* @return Collection<int,AlbumTree> | ||
*/ | ||
public function check(MaintenanceRequest $request): Collection | ||
{ | ||
$albums = Album::query()->join('base_albums', 'base_albums.id', '=', 'albums.id')->select(['albums.id', 'title', 'parent_id', '_lft', '_rgt'])->orderBy('_lft', 'asc')->toBase()->get(); | ||
|
||
return AlbumTree::collect($albums); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Maintenance; | ||
|
||
use App\Http\Requests\BaseApiRequest; | ||
use App\Models\Configs; | ||
use App\Policies\SettingsPolicy; | ||
use App\Rules\AlbumIDRule; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class FullTreeUpdateRequest extends BaseApiRequest | ||
{ | ||
/** | ||
* @var array<int,array{id:string,_lft:int,_rgt:int,parent_id:string|null}> | ||
*/ | ||
private array $albums; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return Gate::check(SettingsPolicy::CAN_EDIT, Configs::class); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'albums' => 'required|array|min:1', | ||
'albums.*' => 'required|array', | ||
'albums.*.id' => ['required', new AlbumIDRule(false)], | ||
'albums.*._lft' => 'required|integer|min:1', | ||
'albums.*._rgt' => 'required|integer|min:1', | ||
'albums.*.parent_id' => [new AlbumIDRule(true)], | ||
]; | ||
} | ||
|
||
protected function processValidatedValues( | ||
array $values, | ||
array $files, | ||
): void { | ||
$this->albums = $values['albums']; | ||
} | ||
|
||
/** | ||
* @return array<int,array{id:string,_lft:int,_rgt:int}> | ||
*/ | ||
public function albums(): array | ||
{ | ||
return $this->albums; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\Diagnostics; | ||
|
||
use App\Models\Album; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\TypeScriptTransformer\Attributes\TypeScript; | ||
|
||
#[TypeScript()] | ||
class AlbumTree extends Data | ||
{ | ||
public function __construct( | ||
public string $id, | ||
public string $title, | ||
public ?string $parent_id, | ||
public int $_lft, | ||
public int $_rgt, | ||
) { | ||
} | ||
|
||
public static function FromModel(Album $album): AlbumTree | ||
{ | ||
return new self( | ||
$album->id, | ||
$album->title, | ||
$album->parent_id, | ||
$album->_lft, | ||
$album->_rgt | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.