/
Version20170824000000.php
83 lines (75 loc) · 3.02 KB
/
Version20170824000000.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Concrete\Core\Updater\Migrations\Migrations;
use Concrete\Core\Attribute\Category\PageCategory;
use Concrete\Core\Entity\Attribute\Key\Settings\AddressSettings;
use Concrete\Core\Entity\Geolocator;
use Concrete\Core\Geolocator\GeolocatorService;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Single as SinglePage;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Updater\Migrations\AbstractMigration;
use Concrete\Core\Updater\Migrations\DirectSchemaUpgraderInterface;
use Concrete\Core\Updater\Migrations\ManagedSchemaUpgraderInterface;
use Concrete\Core\Updater\Migrations\Routine\AddPageDraftsBooleanTrait;
use Doctrine\DBAL\Schema\Schema;
class Version20170824000000 extends AbstractMigration implements ManagedSchemaUpgraderInterface, DirectSchemaUpgraderInterface
{
use AddPageDraftsBooleanTrait;
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Updater\Migrations\ManagedSchemaUpgraderInterface::upgradeSchema()
*/
public function upgradeSchema(Schema $schema)
{
$this->addColumnIfMissing($schema);
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Updater\Migrations\DirectSchemaUpgraderInterface::upgradeDatabase()
*/
public function upgradeDatabase()
{
$this->refreshEntities([
AddressSettings::class,
]);
$this->migrateDrafts();
$app = Application::getFacadeApplication();
// I think this has to be in postUp because it's a completely new table that's not in Schema at all? Bleh.
$this->refreshEntities([
Geolocator::class,
]);
$glService = $app->make(GeolocatorService::class);
/* @var GeolocatorService $glService */
if ($glService->getByHandle('geoplugin') === null) {
$geolocator = Geolocator::create(
'geoplugin',
'geoPlugin'
);
$geolocator
->setGeolocatorConfiguration([
'url' => 'http://www.geoplugin.net/json.gp?ip=[[IP]]',
])
;
$glService->setCurrent($geolocator);
$em = $glService->getEntityManager();
$em->persist($geolocator);
$em->flush($geolocator);
}
$pageAttributeCategory = $app->make(PageCategory::class);
/* @var PageCategory $pageAttributeCategory */
$availableAttributes = [];
foreach (['meta_keywords'] as $akHandle) {
$availableAttributes[$akHandle] = $pageAttributeCategory->getAttributeKeyByHandle($akHandle) ? true : false;
}
$page = Page::getByPath('/dashboard/system/environment/geolocation');
if (!is_object($page) || $page->isError()) {
$sp = SinglePage::add('/dashboard/system/environment/geolocation');
$sp->update(['cName' => 'Geolocation']);
if ($availableAttributes['meta_keywords']) {
$sp->setAttribute('meta_keywords', 'geolocation, ip, address, country, nation, place, locate');
}
}
}
}