Skip to content

Commit

Permalink
EntityCategoryController.php now can update xml_file
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Aug 12, 2024
1 parent f9c7c64 commit 68be235
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Facades/CategoryTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Class CategoryTag facade
*
* @method static false|string create(Entity $entity)
* @method static void delete(Entity $entity)
* @method static false|string delete(Entity $entity)
*/
class CategoryTag extends Facade
{
Expand Down
21 changes: 12 additions & 9 deletions app/Http/Controllers/EntityCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace App\Http\Controllers;

use App\Facades\CategoryTag;
use App\Models\Category;
use App\Models\Entity;
use App\Models\User;
use App\Notifications\IdpCategoryChanged;
use Illuminate\Support\Facades\Notification;

class EntityCategoryController extends Controller
{
Expand All @@ -19,17 +23,16 @@ public function update(Entity $entity)
}

$category = Category::findOrFail(request('category'));

$xml_file = CategoryTag::delete($entity);
if ($xml_file) {
$entity->xml_file = $xml_file;
}
$entity->category()->associate($category);
$entity->xml_file = CategoryTag::create($entity);
$entity->save();
// TODO work with category (not ready)
/* Bus::chain([
new GitDeleteFromCategory($old_category, $entity, Auth::user()),
new GitAddToCategory($category, $entity, Auth::user()),
function () use ($entity, $category) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($admins, new IdpCategoryChanged($entity, $category));
},
])->dispatch();*/
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::send($admins, new IdpCategoryChanged($entity, $category));

if (! $entity->wasChanged()) {
return redirect()
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function update(Request $request, Entity $entity)
$xml_file = $this->deleteTags($updated_entity['metadata']);

DB::transaction(function () use ($entity, $updated_entity, $xml_file) {
$entity->update([
$updateData = [
'name_en' => $updated_entity['name_en'],
'name_cs' => $updated_entity['name_cs'],
'description_en' => $updated_entity['description_en'],
Expand All @@ -232,11 +232,13 @@ public function update(Request $request, Entity $entity)
'sirtfi' => $updated_entity['sirtfi'],
'metadata' => $updated_entity['metadata'],
'xml_file' => $xml_file,
]);
];

if ($entity->type->value === 'idp') {
$entity->update(['rs' => $updated_entity['rs']]);
$updateData['rs'] = $updated_entity['rs'];
}

$entity->update($updateData);
});

if (! $entity->wasChanged()) {
Expand Down

0 comments on commit 68be235

Please sign in to comment.