-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ethercreative/dev
Merge v1.2.0 to Master
- Loading branch information
Showing
11 changed files
with
424 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
migrations/m160606_162300_simpleMap_updateFieldStorage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class m160606_162300_simpleMap_updateFieldStorage extends BaseMigration | ||
{ | ||
public function safeUp() | ||
{ | ||
if (!craft()->db->tableExists('simplemap_maps')) | ||
craft()->plugins->getPlugin('simpleMap')->createTables(); | ||
|
||
$fields = craft()->fields->getAllFields(); | ||
|
||
foreach ($fields as $field) | ||
{ | ||
if ($field->type === 'SimpleMap_Map') | ||
$this->_transferData($field, 'content'); | ||
|
||
if ($field->type === 'Matrix') | ||
foreach (craft()->matrix->getBlockTypesByFieldId($field->id) as $blockType) | ||
foreach ($blockType->getFields() as $blockTypeField) | ||
if ($blockTypeField->type == 'SimpleMap_Map') | ||
$this->_transferData($blockTypeField, 'matrixcontent_' . $field->handle, $blockType->handle . '_' . $blockTypeField->handle); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private function _transferData(FieldModel $field, $tableName, $fieldHandle = "") | ||
{ | ||
if (!$fieldHandle) | ||
$fieldHandle = $field->handle; | ||
|
||
$tableData = craft()->db->createCommand() | ||
->select('elementId, locale, field_' . $fieldHandle) | ||
->from($tableName) | ||
->where('field_' . $fieldHandle . ' IS NOT NULL') | ||
->queryAll(); | ||
|
||
foreach ($tableData as $row) { | ||
$record = new SimpleMap_MapRecord; | ||
$record->ownerId = $row['elementId']; | ||
$record->fieldId = $field->id; | ||
$record->ownerLocale = $row['locale']; | ||
|
||
$f = json_decode($row['field_' . $fieldHandle], true); | ||
|
||
$record->setAttribute('lat', $f['lat']); | ||
$record->setAttribute('lng', $f['lng']); | ||
$record->setAttribute('zoom', $f['zoom']); | ||
$record->setAttribute('address', $f['address']); | ||
if ($f !== null && array_key_exists('parts', $f)) | ||
$record->setAttribute('parts', json_encode($f['parts'])); | ||
|
||
$record->save(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class SimpleMap_MapModel extends BaseModel { | ||
|
||
protected function defineAttributes() | ||
{ | ||
return array( | ||
'ownerId' => AttributeType::Number, | ||
'fieldId' => AttributeType::Number, | ||
'ownerLocale' => AttributeType::Locale, | ||
'lat' => SimpleMap_MapRecord::$dec, | ||
'lng' => SimpleMap_MapRecord::$dec, | ||
'zoom' => AttributeType::Number, | ||
'address' => AttributeType::String, | ||
'parts' => AttributeType::Mixed, | ||
|
||
'distance' => SimpleMap_MapRecord::$dec, | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class SimpleMap_MapRecord extends BaseRecord { | ||
|
||
public static $dec = array(AttributeType::Number, 'column' => ColumnType::Decimal, 'length' => 12, 'decimals' => 8); | ||
const TABLE_NAME = 'simplemap_maps'; | ||
|
||
public function getTableName() | ||
{ | ||
return static::TABLE_NAME; | ||
} | ||
|
||
public function defineRelations() | ||
{ | ||
return array( | ||
'owner' => array(static::BELONGS_TO, 'ElementRecord', 'required' => true, 'onDelete' => static::CASCADE), | ||
'ownerLocale' => array(static::BELONGS_TO, 'LocaleRecord', 'ownerLocale', 'onDelete' => static::CASCADE, 'onUpdate' => static::CASCADE), | ||
'field' => array(static::BELONGS_TO, 'FieldRecord', 'required' => true, 'onDelete' => static::CASCADE) | ||
); | ||
} | ||
|
||
public function defineIndexes() | ||
{ | ||
return array( | ||
array('columns' => array('ownerId')), | ||
array('columns' => array('fieldId')) | ||
); | ||
} | ||
|
||
protected function defineAttributes() | ||
{ | ||
return array( | ||
'ownerLocale' => AttributeType::Locale, | ||
'lat' => SimpleMap_MapRecord::$dec, | ||
'lng' => SimpleMap_MapRecord::$dec, | ||
'zoom' => AttributeType::Number, | ||
'address' => AttributeType::String, | ||
'parts' => AttributeType::Mixed | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.