Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1098904
D11.id16.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Aug 14, 7:27 AM
Size
9 KB
Mime Type
text/x-diff
Expires
Fri, Aug 15, 7:27 AM (3 h, 18 m)
Engine
blob
Format
Raw Data
Handle
711502
Attached To
D11: INP-1313 - Add support for copying content blocks between themes
D11.id16.diff
View Options
Index: core/admin_templates/themes/themes_list.tpl
===================================================================
--- core/admin_templates/themes/themes_list.tpl
+++ core/admin_templates/themes/themes_list.tpl
@@ -7,6 +7,12 @@
<tr>
<td>
<script type="text/javascript">
+ function copy_from_theme($theme_id)
+ {
+ set_hidden_field('copy_from', $theme_id);
+ submit_event('theme','OnCopyData');
+ }
+
//do not rename - this function is used in default grid for double click!
function edit()
{
@@ -24,7 +30,20 @@
function() {
std_delete_items('theme')
} ) );
+ a_toolbar.AddButton( new ToolBarButton('copy', '<inp2:m_phrase label="la_ToolTip_CopyDataFrom" escape="1"/>',
+ function() {
+ themes_menu = menuMgr.createMenu(rs('copy_from_theme_menu'));
+ themes_menu.applyBorder(false, false, false, false);
+ themes_menu.dropShadow("none");
+ themes_menu.showIcon = true;
+ <inp2:m_DefineElement name="theme_elem">
+ themes_menu.addItem(rs('theme<inp2:Field name="ThemeId"/>'),'<inp2:Field name="Name" js_escape="1"/>','javascript:copy_from_theme(<inp2:Field name="ThemeId"/>);');
+ </inp2:m_DefineElement>
+ <inp2:theme.all_PrintList render_as="theme_elem" per_page="-1"/>
+ renderMenus();
+ nls_showMenu(rs('copy_from_theme_menu'), a_toolbar.GetButtonImage('copy'));
+ } ) );
a_toolbar.AddButton( new ToolBarSeparator('sep1') );
@@ -46,6 +65,8 @@
) );
a_toolbar.Render();
+
+
</script>
</td>
@@ -54,9 +75,21 @@
</tbody>
</table>
+<inp2:m_if check="m_Get" var="not_matched_theme_ids">
+ <inp2:m_RenderElement design="form_message">
+ <inp2:m_Phrase label="la_error_SomeOfThemesWerentMatched"/>
+ <inp2:m_DefineElement name="theme_item">
+ <li><inp2:Field name="Name"/></li>
+ </inp2:m_DefineElement>
+ <ul>
+ <inp2:theme.not-matched_PrintList render_as="theme_item" per_page="-1"/>
+ </ul>
+ </inp2:m_RenderElement>
+</inp2:m_if>
+
<inp2:m_RenderElement name="grid" PrefixSpecial="theme" IdField="ThemeId" grid="Default"/>
<script type="text/javascript">
- Grids['theme'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary') );
+ Grids['theme'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary', 'copy') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/english.lang
===================================================================
--- core/install/english.lang
+++ core/install/english.lang
@@ -287,6 +287,7 @@
<PHRASE Label="la_error_RequiredColumnsMissing" Module="Core" Type="1">cmVxdWlyZWQgY29sdW1ucyBtaXNzaW5n</PHRASE>
<PHRASE Label="la_error_RootCategoriesDelete" Module="Core" Type="1">Um9vdCBzZWN0aW9uIG9mIHRoZSBtb2R1bGUocykgY2FuIG5vdCBiZSBkZWxldGVkIQ==</PHRASE>
<PHRASE Label="la_error_SelectItemToMove" Module="Core" Type="1">U2VsZWN0IGF0IGxlYXN0IG9uZSBpdGVtIHRvIG1vdmU=</PHRASE>
+ <PHRASE Label="la_error_SomeOfThemesWerentMatched" Module="Core" Type="1">U29tZSBvZiB0aGVtZXMgd2VyZW4ndCBtYXRjaGVk</PHRASE>
<PHRASE Label="la_error_TemplateFileMissing" Module="Core" Type="1">VGVtcGxhdGUgZmlsZSBpcyBtaXNzaW5n</PHRASE>
<PHRASE Label="la_error_TemporaryTableCopyingFailed" Module="Core" Type="1">Q29weWluZyBvcGVyYXRpb24gaW4gVGVtcG9yYXJ5IHRhYmxlcyBoYXMgZmFpbGVkLiBQbGVhc2UgY29udGFjdCB3ZWJzaXRlIGFkbWluaXN0cmF0b3Iu</PHRASE>
<PHRASE Label="la_error_unique" Module="Core" Type="1">UmVjb3JkIGlzIG5vdCB1bmlxdWU=</PHRASE>
@@ -1609,6 +1610,7 @@
<PHRASE Label="la_ToolTip_CloneUser" Module="Core" Type="1">Q2xvbmUgVXNlcnM=</PHRASE>
<PHRASE Label="la_ToolTip_close" Module="Core" Type="1">Q2xvc2U=</PHRASE>
<PHRASE Label="la_ToolTip_Copy" Module="Core" Type="1">Q29weQ==</PHRASE>
+ <PHRASE Label="la_ToolTip_CopyDataFrom" Module="Core" Type="1">Q29weSBEYXRhIEZyb20=</PHRASE>
<PHRASE Label="la_ToolTip_Cut" Module="Core" Type="1">Q3V0</PHRASE>
<PHRASE Label="la_ToolTip_Decline" Module="Core" Type="1">RGVjbGluZQ==</PHRASE>
<PHRASE Label="la_ToolTip_Delete" Module="Core" Type="1">RGVsZXRl</PHRASE>
Index: core/units/themes/themes_config.php
===================================================================
--- core/units/themes/themes_config.php
+++ core/units/themes/themes_config.php
@@ -59,7 +59,7 @@
'themes_list' => Array (
'prefixes' => Array ('theme_List'), 'format' => "!la_tab_Themes!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'refresh', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'refresh', 'view', 'dbl-click', 'copy'),
),
'themes_edit_general' => Array (
\ No newline at end of file
Index: core/units/themes/themes_eh.php
===================================================================
--- core/units/themes/themes_eh.php
+++ core/units/themes/themes_eh.php
@@ -29,6 +29,7 @@
$permissions = Array(
'OnChangeTheme' => Array('self' => true),
+ 'OnCopyData' => Array('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -161,6 +162,103 @@
}
/**
+ * Copies content blocks between themes
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnCopyData(kEvent $event)
+ {
+ if (!$this->Application->isAdminUser) {
+ return;
+ }
+
+ $source_theme_id = $this->Application->GetVar('copy_from');
+ $this->StoreSelectedIDs($event);
+ $ids=$this->getSelectedIDs($event);
+ $table_name = $this->Application->getUnitConfig('c')->getTableName();
+ $content_table_name = $this->Application->getUnitConfig('content')->getTableName();
+ $page_revision_table_name = $this->Application->getUnitConfig('page-revision')->getTableName();
+ $not_matched_theme_ids = Array ();
+
+ foreach($ids as $target_theme_id)
+ {
+ if ( $target_theme_id == $source_theme_id ) {
+ continue;
+ }
+
+ // get matching templates
+ $sql = 'SELECT source.LiveRevisionNumber, source.CategoryId AS SourceCategoryId, target.CategoryId AS TargetCategoryId, source.Template
+ FROM ' . $table_name . ' source
+ LEFT JOIN ' . $table_name . ' target
+ ON target.ThemeId = ' . $target_theme_id . ' AND target.Template = source.Template
+ WHERE source.ThemeId = ' . $source_theme_id . '
+ HAVING NOT ISNULL(TargetCategoryId)';
+ $matches = $this->Conn->Query($sql);
+
+ if ( count($matches) ) {
+ // delete all target blocks
+ $sql = 'SELECT CategoryId
+ FROM ' . $table_name . '
+ WHERE ThemeId = ' . $target_theme_id;
+ $target_categories = implode(',', $this->Conn->GetCol($sql));
+ $sql = 'DELETE FROM ' . $content_table_name . '
+ WHERE PageId IN (' . $target_categories . ')';
+ $this->Conn->Query($sql);
+ $sql = 'DELETE FROM ' . $page_revision_table_name . '
+ WHERE PageId IN (' . $target_categories . ')';
+ $this->Conn->Query($sql);
+
+ foreach ($matches as $match) {
+ if ( !$match['LiveRevisionNumber'] ) {
+ continue;
+ }
+
+ $sql = 'SELECT *
+ FROM ' . $page_revision_table_name . '
+ WHERE PageId = ' . $match['SourceCategoryId'] . ' AND RevisionNumber =' . $match['LiveRevisionNumber'];
+ $revision = $this->Conn->GetRow($sql);
+
+ if ( !$revision ) {
+ continue;
+ }
+
+ $revision['PageId'] = $match['TargetCategoryId'];
+ $revision['RevisionNumber'] = 1;
+ $live_revision_id = $revision['RevisionId'];
+ unset($revision['RevisionId']);
+ $this->Conn->doInsert($revision, $page_revision_table_name);
+ $new_revision_id = $this->Conn->getInsertID();
+
+ $sql = 'UPDATE ' . $table_name . '
+ SET LiveRevisionNumber = 1
+ WHERE CategoryId = ' . $match['TargetCategoryId'];
+ $this->Conn->Query($sql);
+
+ $sql = 'SELECT *
+ FROM ' . $content_table_name . '
+ WHERE PageId = ' . $match['SourceCategoryId'] . ' AND RevisionId =' . $live_revision_id;
+ $blocks = $this->Conn->Query($sql);
+
+ foreach ($blocks as $block) {
+ $block['RevisionId'] = $new_revision_id;
+ $block['PageId'] = $match['TargetCategoryId'];
+ unset($block['PageContentId']);
+ $this->Conn->doInsert($block, $content_table_name);
+ }
+ }
+ } else {
+ $not_matched_theme_ids[] = $target_theme_id;
+ }
+ }
+
+ if ( count($not_matched_theme_ids) ) {
+ $event->setRedirectParam('not_matched_theme_ids',implode(',', $not_matched_theme_ids));
+ }
+ }
+
+ /**
* Apply system filter to themes list
*
* @param kEvent $event
@@ -194,6 +292,10 @@
if ( strlen($themes) ) {
$themes = explode('|', substr($themes, 1, -1));
$object->addFilter('domain_filter', '%1$s.ThemeId IN (' . implode(',', $themes) . ')');
+ }
+
+ if ( $event->Special == 'not-matched' ) {
+ $object->addFilter('not_matched_filter', '%1$s.ThemeId IN (' . $this->Application->GetVar('not_matched_theme_ids') . ')');
}
}
}
Event Timeline
Log In to Comment