Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -5,17 +5,17 @@ namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Symfony\Component\Filesystem\Filesystem;
use Thelia\Core\Event\Lang\LangEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Template\TemplateHelper;
use Thelia\Core\Translation\Translator;
use Thelia\Model\Base\Lang as BaseLang;
use Thelia\Model\Map\LangTableMap;
class Lang extends BaseLang
{
// Constants to define behavior when a request string does not exists in the current language
const STRICTLY_USE_REQUESTED_LANGUAGE = 0;
const REPLACE_BY_DEFAULT_LANGUAGE = 1;
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
protected static $defaultLanguage;
@@ -43,50 +43,25 @@ class Lang extends BaseLang
if ($this->getId() === null) {
throw new \RuntimeException("impossible to just uncheck default language, choose a new one");
}
$con = Propel::getWriteConnection(LangTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
LangQuery::create()
->filterByByDefault(1)
->update(array('ByDefault' => 0), $con);
if (!$this->getByDefault()) {
$con = Propel::getWriteConnection(LangTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
LangQuery::create()
->filterByByDefault(1)
->update(array('ByDefault' => 0), $con);
$this
->setByDefault(1)
->save($con);
$this
->setVisible(1)
->setActive(1)
->setByDefault(1)
->save($con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
protected function fixMissingFlag()
{
// Be sure that a lang have a flag, otherwise copy the
// "unknown" flag
$adminTemplate = TemplateHelper::getInstance()->getActiveAdminTemplate();
$unknownFlag = ConfigQuery::getUnknownFlagPath();
$unknownFlagPath = $adminTemplate->getAbsolutePath().DS.$unknownFlag;
if (! file_exists($unknownFlagPath)) {
throw new \RuntimeException(
Translator::getInstance()->trans(
"The image which replaces an undefined country flag (%file) was not found. Please check unknown-flag-path configuration variable, and check that the image exists.",
array("%file" => $unknownFlag)
)
);
}
// Check if the country flag exists
$countryFlag = rtrim(dirname($unknownFlagPath), DS).DS.$this->getCode().'.png';
if (! file_exists($countryFlag)) {
$fs = new Filesystem();
$fs->copy($unknownFlagPath, $countryFlag);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
}
@@ -101,7 +76,7 @@ class Lang extends BaseLang
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATELANG, new LangEvent($this));
$this->fixMissingFlag();
$this->dispatchEvent(TheliaEvents::LANG_FIX_MISSING_FLAG, new LangEvent($this));
}
public function preUpdate(ConnectionInterface $con = null)
@@ -115,7 +90,7 @@ class Lang extends BaseLang
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATELANG, new LangEvent($this));
$this->fixMissingFlag();
$this->dispatchEvent(TheliaEvents::LANG_FIX_MISSING_FLAG, new LangEvent($this));
}
public function preDelete(ConnectionInterface $con = null)
@@ -132,7 +107,11 @@ class Lang extends BaseLang
public function preSave(ConnectionInterface $con = null)
{
$this->setDatetimeFormat(sprintf("%s %s", $this->getDateFormat(), $this->getTimeFormat()));
// If the date/time format is not specified, generate it.
$dateTimeFormat = $this->getDateTimeFormat();
if (empty($dateTimeFormat)) {
$this->setDatetimeFormat(sprintf("%s %s", $this->getDateFormat(), $this->getTimeFormat()));
}
return true;
}