Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix/1745 #16

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
php-versions: [ '8.1', '8.2' ]
php-versions: [ '8.1', '8.3' ]
coverage: [none]
fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion lib/GaletteAuto/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function delete($ids)
' from ids `' . implode(' - ', $ids) . '` | ' . $e->getMessage(),
Analog::WARNING
);
return false;
throw $e;
}
}

Expand Down
32 changes: 24 additions & 8 deletions lib/GaletteAuto/Controllers/Crud/ModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ public function doEdit(Request $request, Response $response, int $id = null, $ac
$this->session->auto_model = $post;
if (!$is_new) {
$id = $post[Model::PK];
$route = $this->routeparser->urlFor(
'modelEdit',
[
'id' => $id
]
);
} else {
$route = $this->routeparser->urlFor('modelAdd');
}
$route = $this->routeparser->urlFor(
'modelEdit',
[
'action' => $action,
'id' => $id
]
);

foreach ($error_detected as $error) {
$this->flash->addMessage(
Expand Down Expand Up @@ -401,7 +402,22 @@ protected function doDelete(array $args, array $post): bool
$ids = $post['id'];
}

return $model->delete($ids);
try {
return $model->delete($ids);
} catch (\Throwable $e) {
if ($this->zdb->isForeignKeyException($e)) {
$this->flash->addMessage(
'error_detected',
_T("This model is used by one or more vehicles, it cannot be deleted.", "auto")
);
} else {
$this->flash->addMessage(
'error_detected',
_T("An error occurred while deleting model.", "auto")
);
}
return false;
}
}

// /CRUD - Delete
Expand Down
51 changes: 28 additions & 23 deletions lib/GaletteAuto/Controllers/Crud/PropertiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* Galette Auto plugin controller for properties (brands, models, colors, ...)
*
* @category Plugins
* @name Autos
* @name PropertiesList
* @package GaletteAuto
* @author Johan Cwiklinski <[email protected]>
* @copyright 2017-2023 The Galette Team
Expand Down Expand Up @@ -609,37 +609,42 @@ public function doRemoveProperty(Request $request, Response $response, string $p
$ids = $post['id'];
}

$model = new Model($this->zdb);
$del = $model->delete($ids);

$classname = AbstractObject::getClassForPropName($property);
$object = new $classname($this->zdb);
$del = $object->delete($ids);

if ($del !== true) {
$error_detected = str_replace(
'%property',
$object->getFieldLabel(),
_T('An error occurred trying to remove %property :/', 'auto')
);

$this->flash->addMessage(
'error_detected',
$error_detected
);
} else {
$success_detected = str_replace(
['%count', '%property'],
[count($ids), $object->getFieldLabel()],
_T("%count %property have been successfully deleted.", "auto")
);
try {
$object->delete($ids);

$this->flash->addMessage(
'success_detected',
$success_detected
str_replace(
['%count', '%property'],
[count($ids), $object->getFieldLabel()],
_T("%count %property have been successfully deleted.", "auto")
)
);

$success = true;
} catch (\Throwable $e) {
if ($this->zdb->isForeignKeyException($e)) {
$this->flash->addMessage(
'error_detected',
str_replace(
'%property',
mb_strtolower($object->getFieldLabel()),
_T("This %property is used by one or more vehicles, it cannot be deleted.", "auto")
)
);
} else {
$this->flash->addMessage(
'error_detected',
str_replace(
'%property',
$object->getFieldLabel(),
_T('An error occurred trying to remove %property :/', 'auto')
)
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/GaletteAuto/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function delete($ids)
implode(' - ', $ids) . '` | ' . $e->getMessage(),
Analog::WARNING
);
return false;
throw $e;
}
}

Expand Down