mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-10 15:26:10 -06:00
#452 Bug fixed related the System language on posting ads
This commit is contained in:
parent
e73d9e3da3
commit
3e96d1d116
@ -0,0 +1,43 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv\Listener;
|
||||
|
||||
use Anomaly\SettingsModule\Setting\SettingsWereSaved;
|
||||
|
||||
class DefaultLocaleAddEnv
|
||||
{
|
||||
|
||||
public function setEnvironmentValue(array $values)
|
||||
{
|
||||
|
||||
$envFile = app()->environmentFilePath();
|
||||
$str = file_get_contents($envFile);
|
||||
|
||||
if (count($values) > 0) {
|
||||
foreach ($values as $envKey => $envValue) {
|
||||
|
||||
$str .= "\n"; // In case the searched variable is in the last line without \n
|
||||
$keyPosition = strpos($str, "{$envKey}=");
|
||||
$endOfLinePosition = strpos($str, "\n", $keyPosition);
|
||||
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
|
||||
|
||||
// If key does not exist, add it
|
||||
if (!$keyPosition || !$endOfLinePosition || !$oldLine) {
|
||||
$str .= "{$envKey}={$envValue}\n";
|
||||
} else {
|
||||
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$str = substr($str, 0, -1);
|
||||
if (!file_put_contents($envFile, $str)) return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function handle(SettingsWereSaved $event)
|
||||
{
|
||||
$this->setEnvironmentValue(['APP_FALLBACK_LOCALE' => strtoupper($event->getBuilder()->getPostValue('default_locale'))]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php namespace Visiosoft\AdvsModule;
|
||||
|
||||
use Anomaly\SettingsModule\Setting\SettingsWereSaved;
|
||||
use Anomaly\Streams\Platform\Addon\AddonCollection;
|
||||
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
|
||||
use Anomaly\Streams\Platform\Model\Location\LocationVillageEntryModel;
|
||||
@ -8,6 +9,7 @@ use Visiosoft\AdvsModule\Adv\AdvRepository;
|
||||
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
|
||||
use Visiosoft\AdvsModule\Adv\AdvModel;
|
||||
use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder;
|
||||
use Visiosoft\AdvsModule\Adv\Listener\DefaultLocaleAddEnv;
|
||||
use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Village\VillageRepository;
|
||||
use Visiosoft\LocationModule\Village\VillageModel;
|
||||
@ -225,9 +227,9 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
|
||||
* @type array|null
|
||||
*/
|
||||
protected $listeners = [
|
||||
//Visiosoft\AdvsModule\Event\ExampleEvent::class => [
|
||||
// Visiosoft\AdvsModule\Listener\ExampleListener::class,
|
||||
//],
|
||||
SettingsWereSaved::class => [
|
||||
DefaultLocaleAddEnv::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user