|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Dealer\Service; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use ColissimoLabel\Exception\Exception; |
|
8
|
|
|
use Dealer\Model\Dealer; |
|
9
|
|
|
use Dealer\Model\DealerQuery; |
|
10
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
|
11
|
|
|
use Propel\Runtime\Propel; |
|
12
|
|
|
use Propel\Runtime\ServiceContainer\ServiceContainerInterface; |
|
13
|
|
|
use Thelia\Install\Database; |
|
14
|
|
|
use Thelia\Model\CountryQuery; |
|
15
|
|
|
use Thelia\Model\Lang; |
|
16
|
|
|
|
|
17
|
|
|
class UpdateTablesService |
|
18
|
|
|
{ |
|
19
|
|
|
const SERVICE_ID = 'dealer.command.update_tables'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return array|string |
|
23
|
|
|
*/ |
|
24
|
|
|
public function updateTables() |
|
25
|
|
|
{ |
|
26
|
|
|
$query = "SELECT id, address1, address2, zipcode, city, country, latitude, longitude, company, description FROM `dealer_tab`"; |
|
27
|
|
|
|
|
28
|
|
|
$connection = Propel::getConnection(); |
|
29
|
|
|
try { |
|
30
|
|
|
$stmt = $connection->prepare($query); |
|
31
|
|
|
$stmt->execute(); |
|
32
|
|
|
|
|
33
|
|
|
$countriesNotFound = []; |
|
34
|
|
|
while ($results = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
35
|
|
|
$country = CountryQuery::create() |
|
36
|
|
|
->useCountryI18nQuery() |
|
37
|
|
|
->filterByTitle('%' . $results['country'] . '%', Criteria::LIKE) |
|
38
|
|
|
->endUse() |
|
39
|
|
|
->findOne() |
|
40
|
|
|
; |
|
41
|
|
|
|
|
42
|
|
|
if (null === $country) { |
|
43
|
|
|
$country = 64; |
|
44
|
|
|
$countriesNotFound[] = $results ['country']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$now = new \DateTime(); |
|
48
|
|
|
|
|
49
|
|
|
$dealer = new Dealer(); |
|
50
|
|
|
$dealer |
|
51
|
|
|
->setVisible(true) |
|
52
|
|
|
->setAddress1($results['address1']) |
|
53
|
|
|
->setAddress2($results['address2']) |
|
54
|
|
|
->setZipcode($results['zipcode']) |
|
55
|
|
|
->setCity($results['city']) |
|
56
|
|
|
->setCountry($country) |
|
57
|
|
|
->setLatitude($results['latitude']) |
|
58
|
|
|
->setLongitude($results['longitude']) |
|
59
|
|
|
->setCreatedAt($now) |
|
60
|
|
|
->setUpdatedAt($now) |
|
61
|
|
|
->setLocale(Lang::getDefaultLanguage()->getLocale()) |
|
62
|
|
|
->setTitle($results['company']) |
|
63
|
|
|
->setDescription($results['description']) |
|
64
|
|
|
->save() |
|
65
|
|
|
; |
|
66
|
|
|
} |
|
67
|
|
|
} catch (\Exception $exception) { |
|
68
|
|
|
return $exception->getMessage(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $countriesNotFound; |
|
72
|
|
|
} |
|
73
|
|
|
} |