This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathm160509_000000_seomatic_addSiteLinksBing.php
65 lines (53 loc) · 2.05 KB
/
m160509_000000_seomatic_addSiteLinksBing.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
<?php
namespace Craft;
/**
* The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName
*/
class m160509_000000_seomatic_addSiteLinksBing extends BaseMigration
{
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
// specify columns and AttributeType
$newColumns = array (
'siteLinksSearchTargets' => ColumnType::Text,
'siteLinksQueryInput' => ColumnType::Varchar,
);
$this->_addColumnsAfter("seomatic_settings", $newColumns, "siteRobotsTxt");
// specify columns and AttributeType
$newColumns = array (
'bingSiteVerification' => ColumnType::Varchar,
);
$this->_addColumnsAfter("seomatic_settings", $newColumns, "googleSiteVerification");
// return true and let craft know its done
return true;
}
private function _addColumnsAfter($tableName, $newColumns, $afterColumnHandle)
{
// this is a foreach loop, enough said
foreach ($newColumns as $columnName => $columnType)
{
// check if the column does NOT exist
if (!craft()->db->columnExists($tableName, $columnName))
{
$this->addColumnAfter($tableName, $columnName, array(
'column' => $columnType,
'null' => false,
),
$afterColumnHandle
);
// log that we created the new column
SeomaticPlugin::log("Created the `$columnName` in the `$tableName` table.", LogLevel::Info, true);
}
// if the column already exists in the table
else {
// tell craft that we couldn't create the column as it alredy exists.
SeomaticPlugin::log("Column `$columnName` already exists in the `$tableName` table.", LogLevel::Info, true);
}
}
}
}