Skip to content

Commit 872e110

Browse files
authored
Merge pull request #130 from openclassify/emrullahardc-patch-2
TranslateFixer added.
2 parents 41a1042 + 61462fc commit 872e110

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/Adv/AdvObserver.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,52 @@
66
use Anomaly\Streams\Platform\Entry\EntryObserver;
77
use Visiosoft\AdvsModule\Adv\Event\DeletedAd;
88
use Visiosoft\AdvsModule\Adv\Event\DeletingAd;
9+
use Illuminate\Support\Facades\DB;
910

1011
class AdvObserver extends EntryObserver
1112
{
13+
private function translateFixer($entryId)
14+
{
15+
//TODO:: Use single query
16+
$defaultLocale = setting_value('streams::default_locale');
17+
$translations = DB::table('advs_advs_translations')
18+
->select(['locale', 'name'])
19+
->where('entry_id', $entryId)
20+
->whereNotNull('locale')
21+
->get();
22+
23+
if ($translations) {
24+
$name = "";
25+
foreach ($translations as $translation) {
26+
if ($translation->locale == $defaultLocale && !empty($translation->name)) {
27+
$name = $translation->name;
28+
break;
29+
} else if (!empty($translation->name)) {
30+
$name = $translation->name;
31+
}
32+
}
33+
34+
DB::table('advs_advs_translations')
35+
->whereNull('name')
36+
->where('entry_id', $entryId)
37+
->update(['name' => $name]);
38+
}
39+
40+
}
41+
42+
public function created(EntryInterface $entry)
43+
{
44+
$this->translateFixer($entry->getId());
45+
}
46+
47+
public function updated(EntryInterface $entry)
48+
{
49+
$this->translateFixer($entry->getId());
50+
}
51+
1252
public function updating(EntryInterface $entry)
1353
{
1454
$this->dispatchSync(new AddSlug($entry));
15-
1655
parent::updating($entry);
1756
}
1857

0 commit comments

Comments
 (0)