Skip to content

Commit

Permalink
version 0.3.5
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Crawford <[email protected]>
  • Loading branch information
engram-design committed Sep 20, 2015
1 parent 7c46fc7 commit 6d3c4a1
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ Thanks go to [@brandonkelly](https://github.com/brandonkelly) and [@benparizek](

## Changelog

#### 0.3.5

- Change to content table naming when inside Matrix field. When two Super Table fields in different Matrix fields had the same handle, when one ST field was deleted, content for both would be deleted. Now prefixes tables with Matrix field id - ie: `supertablecontent_matrixId_fieldhandle`.
- Fix for some UI elements not initializing for Matrix > Super Table > Matrix layout [#28](https://github.com/engram-design/SuperTable/issues/28).


#### 0.3.4

- Minor visual fix for Row layout and table overflow [#24](https://github.com/engram-design/SuperTable/issues/24).
Expand Down
2 changes: 1 addition & 1 deletion supertable/SuperTablePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getName()

public function getVersion()
{
return '0.3.4';
return '0.3.5';
}

public function getDeveloper()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
namespace Craft;

class m150901_144609_superTable_fixForContentTables extends BaseMigration
{
public function safeUp()
{
// Get all Super Table fields - but only the ones inside Matrix fields
$fields = craft()->fields->getAllFields();
$superTableFields = array();

foreach ($fields as $field) {
if ($field->type == 'Matrix') {
$blockTypes = craft()->matrix->getBlockTypesByFieldId($field->id);

foreach ($blockTypes as $blockType) {
foreach ($blockType->getFields() as $blockTypeField) {
if ($blockTypeField->type == 'SuperTable') {
$superTableFields[] = array(
'field' => $blockTypeField,
'parentFieldId' => $blockType->id,
);
}
}
}
}
}

// Now, we need to create new tables which incorporate the Matrix field this Super Table is sitting inside.
// This will mean the supertablecontent_fieldhandle tables will now include the Matrix field id.
//
// So, we need to duplicate each table structure and content into new tables. We aren't removing the old tables
// so as not to be destructive, and potentially loose content somwehere along the way.
foreach ($superTableFields as $options) {
$field = $options['field'];
$parentFieldId = $options['parentFieldId'];

// The latest code will actually mean this points to the new table already!
$newContentTable = craft()->superTable->getContentTableName($field);

if (!craft()->db->tableExists($newContentTable)) {
$oldContentTable = str_replace('_'.$parentFieldId, '', $newContentTable);

// Grab all existing data from old table
$tableData = craft()->db->createCommand()
->select('*')
->from($oldContentTable)
->queryAll();

// Get the table creation raw SQL
$tableSchema = craft()->db->createCommand('SHOW CREATE TABLE craft_' . $oldContentTable)->queryRow();
$newTableSql = $tableSchema['Create Table'];

// Create the new table
$newTableSql = str_replace($oldContentTable, $newContentTable, $newTableSql);
craft()->db->createCommand($newTableSql)->execute();

// Copy the existing data into newly created table
if ($tableData) {
$columns = array_keys($tableData[0]);
$rows = array();

foreach ($tableData as $key => $row) {
$rows[] = array_values($row);
}

foreach ($columns as $key => $column) {

// Craft does these fields for us.
if ($column == 'dateCreated' || $column == 'dateUpdated' || $column == 'uid') {
unset($columns[$key]);
}
}

// In the new content goes!
craft()->db->createCommand()->insertAll($newContentTable, $columns, $rows);
}
}
}

return true;
}
}
20 changes: 10 additions & 10 deletions supertable/resources/js/MatrixConfiguratorAlt.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ var BlockType = Garnish.Base.extend(
});


Field = Garnish.Base.extend(
var Field = Garnish.Base.extend(
{
configurator: null,
blockType: null,
Expand Down Expand Up @@ -580,6 +580,8 @@ Field = Garnish.Base.extend(
{
this.selectedFieldType = this.$typeSelect.val();
this.initializedFieldTypeSettings[this.selectedFieldType] = this.$typeSettingsContainer.children();

this.setFieldType(this.selectedFieldType);
}

if (!this.$handleInput.val())
Expand Down Expand Up @@ -670,12 +672,13 @@ Field = Garnish.Base.extend(

var firstTime = (typeof this.initializedFieldTypeSettings[type] == 'undefined');

var info = this.configurator.getFieldTypeInfo(type),
bodyHtml = this.getParsedFieldTypeHtml(info.settingsBodyHtml),
footHtml = this.getParsedFieldTypeHtml(info.settingsFootHtml);

if (firstTime)
{
var info = this.configurator.getFieldTypeInfo(type),
bodyHtml = this.getParsedFieldTypeHtml(info.settingsBodyHtml),
footHtml = this.getParsedFieldTypeHtml(info.settingsFootHtml),
$body = $('<div>'+bodyHtml+'</div>');
var $body = $('<div>'+bodyHtml+'</div>');

this.initializedFieldTypeSettings[type] = $body;
}
Expand All @@ -686,11 +689,8 @@ Field = Garnish.Base.extend(

$body.appendTo(this.$typeSettingsContainer);

if (firstTime)
{
Craft.initUiElements($body);
Garnish.$bod.append(footHtml);
}
Craft.initUiElements($body);
Garnish.$bod.append(footHtml);
},

getParsedFieldTypeHtml: function(html)
Expand Down
14 changes: 12 additions & 2 deletions supertable/resources/js/SuperTableConfigurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,23 @@ Craft.SuperTableSettingsModal = Garnish.Modal.extend({

this.$fieldSettings = this.$settingsContainer.appendTo($main);

Craft.initUiElements(this.$fieldSettings);
Garnish.$bod.append(this.fieldTypeFootHtml);
// Give the modal window some time to get it together
setTimeout($.proxy(function() {
Craft.initUiElements(this.$fieldSettings);
Garnish.$bod.append(this.fieldTypeFootHtml);
}, this), 1);

this.addListener(this.$closeBtn, 'activate', 'closeModal');
},

restoreSettingsToTable: function() {

// Special case for Matrix - reset field back to defaults, otherwise causes UI havok
this.$fieldSettings.find('.matrixconfigitem.sel').removeClass('sel');
this.$fieldSettings.find('.mc-sidebar.fields .col-inner-container').addClass('hidden');
this.$fieldSettings.find('.field-settings .col-inner-container').addClass('hidden');
this.$fieldSettings.find('.field-settings .col-inner-container .items div[data-id]').addClass('hidden');

this.field.restoreSettingsHtml(this.$fieldSettings);
},

Expand Down
14 changes: 14 additions & 0 deletions supertable/services/SuperTableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ public function deleteSuperTableField(FieldModel $superTableField)
public function getContentTableName(FieldModel $superTableField, $useOldHandle = false)
{
$name = '';
$parentFieldId = '';

do {
if ($useOldHandle) {
Expand All @@ -429,10 +430,23 @@ public function getContentTableName(FieldModel $superTableField, $useOldHandle =
$handle = $superTableField->handle;
}

// Check if this field is inside a Matrix - we need to prefix this content table if so.
if ($superTableField->context != 'global') {
$parentFieldContext = explode(':', $superTableField->context);

if ($parentFieldContext[0] == 'matrixBlockType') {
$parentFieldId = $parentFieldContext[1];
}
}

$name = '_'.StringHelper::toLowerCase($handle).$name;
}
while ($superTableField = $this->getParentSuperTableField($superTableField));

if ($parentFieldId) {
$name = '_'.$parentFieldId.$name;
}

return 'supertablecontent'.$name;
}

Expand Down

0 comments on commit 6d3c4a1

Please sign in to comment.