-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.php
More file actions
58 lines (48 loc) · 1.55 KB
/
controller.php
File metadata and controls
58 lines (48 loc) · 1.55 KB
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
<?php
namespace Concrete\Package\OunziwOsm;
defined('C5_EXECUTE') or die('Access Denied.');
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Package\Package;
class Controller extends Package
{
protected $pkgHandle = 'ounziw_osm';
protected $appVersionRequired = '9.0';
protected $pkgVersion = '2.1.1';
public function getPackageDescription()
{
return t('Displays a map using OpenStreetMap and Leaflet.');
}
public function getPackageName()
{
return t('Free Map');
}
public function install()
{
$pkg = parent::install();
BlockType::installBlockType('ounziw_osm_map', $pkg);
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::upgrade()
*/
public function upgrade()
{
parent::upgrade();
$cn = $this->app->make(Connection::class);
foreach (['width', 'height'] as $field) {
foreach ($cn->fetchFirstColumn("SELECT DISTINCT {$field} FROM btOunziwosmmap") as $originalValue) {
$newValue = (string) $originalValue;
if ($newValue === '') {
$newValue = $field === 'width' ? '300px' : '200px';
} elseif (preg_match('/^\d+$/', $newValue)) {
$newValue .= 'px';
}
if ($newValue !== $originalValue) {
$cn->update('btOunziwosmmap', [$field => $newValue], [$field => $originalValue]);
}
}
}
}
}