);
}
+ $warning_detected = $ptype->getWarnings();
+ if (count($warning_detected)) {
+ foreach ($warning_detected as $warning) {
+ $this->flash->addMessage(
+ 'warning_detected',
+ $warning
+ );
+ }
+ }
+
return $response
->withStatus(301)
->withHeader('Location', $this->router->pathFor('paymentTypes'));
$e->getMessage()
);
}
+ } finally {
+ $warning_detected = $ptype->getWarnings();
+ if (count($warning_detected)) {
+ foreach ($warning_detected as $warning) {
+ $this->flash->addMessage(
+ 'warning_detected',
+ $warning
+ );
+ }
+ }
}
}
$ptype->name = $post['name'];
$res = $ptype->store();
+ $warning_detected = $ptype->getWarnings();
+ if (count($warning_detected)) {
+ foreach ($warning_detected as $warning) {
+ $this->flash->addMessage(
+ 'warning_detected',
+ $warning
+ );
+ }
+ }
+
if (!$res) {
$this->flash->addMessage(
'error_detected',
use Galette\Core\Db;
use Galette\Entity\DynamicFieldsHandle;
use Galette\Entity\TranslatableTrait;
+use Galette\Entity\I18nTrait;
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Predicate\Expression as PredicateExpression;
abstract class DynamicField
{
use TranslatableTrait;
+ use I18nTrait;
const TABLE = 'field_types';
const PK = 'field_id';
protected $form;
protected $errors;
- protected $warnings;
protected $zdb;
}
if ($this->old_name !== null) {
- $deleted = \deleteDynamicTranslation($this->old_name);
- if ($deleted === false) {
- $this->warnings[] = str_replace(
- '%field',
- $this->old_name,
- _T('Unable to remove old dynamic translation for %field :(')
- );
- }
-
- $added = \addDynamicTranslation($this->name);
- if ($added === false) {
- $this->warnings[] = str_replace(
- '%field',
- $this->name,
- _T('Unable to add dynamic translation for %field :(')
- );
- }
+ $this->deleteTranslation($this->old_name);
+ $this->addTranslation($this->name);
}
try {
}
if ($this->name != '') {
- $translated = \addDynamicTranslation($this->name);
- if (!$translated) {
- $this->warnings[] = str_replace(
- '%field',
- $this->name,
- _T('Unable to add dynamic translation for %field :(')
- );
- }
+ $this->addTranslation($this->name);
}
}
} catch (Exception $e) {
\Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
);
}
- \deleteDynamicTranslation($this->name);
+ $this->deleteTranslation($this->name);
$this->zdb->connection->commit();
return true;
trait I18nTrait
{
+ protected $warnings = [];
+
/**
* Add a translation stored in the database
*
Analog::INFO
);
- $where = array();
$owhere = $select->where;
$update = $this->zdb->update(L10n::TABLE);
$text_orig . '` | ' . $e->getMessage(),
Analog::ERROR
);
- throw $e;
+
+ $this->warnings[] = str_replace(
+ '%field',
+ $text_orig,
+ _T('Unable to add dynamic translation for %field :(')
+ );
+
+ return false;
}
}
*
* @return boolean
*/
- protected function updateDynamicTranslation($text_orig, $text_locale, $text_trans)
+ protected function updateTranslation($text_orig, $text_locale, $text_trans)
{
try {
//check if translation already exists
);
if ($exists) {
- $where = array();
$owhere = $select->where;
$update = $this->zdb->update(L10n::TABLE);
$text_orig . '` | ' . $e->getMessage(),
Analog::ERROR
);
+
+ $this->warnings[] = str_replace(
+ '%field',
+ $text_orig,
+ _T('Unable to update dynamic translation for %field :(')
+ );
+
return false;
}
}
*/
protected function deleteTranslation($text_orig)
{
- global $i18n;
-
try {
$delete = $this->zdb->delete(L10n::TABLE);
$delete->where(
} catch (Exception $e) {
Analog::log(
'An error occurred deleting dynamic translation for `' .
- $text_orig . '` (lang `' . $lang->getLongID() . '`) | ' .
- $e->getMessage(),
+ $text_orig . ' | ' . $e->getMessage(),
Analog::ERROR
);
- throw $e;
+
+ $this->warnings[] = str_replace(
+ '%field',
+ $text_orig,
+ _T('Unable to remove old dynamic translation for %field :(')
+ );
+
+ return false;
}
}