Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions assets/js/content-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ jQuery( document ).ready(function($) {
* cleared.
*/
editBatch: function() {
var self = this;
var batchId = $('#sme-batch-id').html();
var titleObj = $('input[name="batch_title"]');
var posts = $('.sme-select-post');
var postIdsObj = $('input[name="post_ids"]');
var postIds = [];
var selectAll = $('[id^=cb-select-all-]');
var self = this;
var batchId = $('#sme-batch-id').html();
var titleObj = $('input[name="batch_title"]');
var posts = $('.sme-select-post');
var postIdsObj = $('input[name="post_ids"]');
var postIds = [];
var selectAll = $('[id^=cb-select-all-]');
var selectAllPosts = $('.posts [id^=cb-select-all-]');
var cookie;
var batch;

Expand Down Expand Up @@ -118,17 +119,20 @@ jQuery( document ).ready(function($) {
self.updateSelectedPosts(batchId, postIds, postIdsObj, titleObj.val());
});

// User has selected/unselected all posts.
// User has selected/unselected all pages or menu items.
selectAll.click(function() {
var isChecked = $(this).prop('checked');

posts.each(function() {
self.selectPost(postIds, parseInt($(this).val()), isChecked);
});
});

// User has selected/unselected all posts.
selectAllPosts.click(function() {
// Update selected posts.
self.updateSelectedPosts(batchId, postIds, postIdsObj, titleObj.val());
});

},

/**
Expand Down
53 changes: 27 additions & 26 deletions classes/class-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,28 @@ public function register_post_types() {
}

public function register_menu_pages() {
add_menu_page( 'Content Staging', 'Content Staging', apply_filters( 'sme-list-batches-capability', 'manage_options' ), 'sme-list-batches', array( $this->batch_ctrl, 'list_batches' ) );
add_submenu_page( 'sme-list-batches', 'History', 'History', apply_filters( 'sme-batch-history-capability', 'manage_options' ), 'sme-batch-history', array( $this->batch_history_ctrl, 'init' ) );
add_submenu_page( 'sme-list-batches', 'Settings', 'Settings', apply_filters( 'sme-settings-capability', 'manage_options' ), 'sme-settings', array( $this->settings_ctrl, 'init' ) );
add_submenu_page( 'sme-list-batches', 'WordPress Options', 'WordPress Options', apply_filters( 'sme-wp-options-capability', 'manage_options' ), 'sme-wp-options', array( $this->options_ctrl, 'init' ) );
add_submenu_page( null, 'Edit Batch', 'Edit', apply_filters( 'sme-edit-batch-capability', 'manage_options' ), 'sme-edit-batch', array( $this->batch_ctrl, 'edit_batch' ) );
add_submenu_page( null, 'Delete Batch', 'Delete', apply_filters( 'sme-delete-batch-capability', 'manage_options' ), 'sme-delete-batch', array( $this->batch_ctrl, 'confirm_delete_batch' ) );
add_submenu_page( null, 'Pre-Flight Batch', 'Pre-Flight', apply_filters( 'sme-preflight-batch-capability', 'manage_options' ), 'sme-preflight-batch', array( $this->batch_ctrl, 'prepare' ) );
add_submenu_page( null, 'Quick Deploy Batch', 'Quick Deploy', apply_filters( 'sme-quick-deploy-batch-capability', 'manage_options' ), 'sme-quick-deploy-batch', array( $this->batch_ctrl, 'quick_deploy' ) );
add_submenu_page( null, 'Deploy Batch', 'Deploy', apply_filters( 'sme-send-batch-capability', 'manage_options' ), 'sme-send-batch', array( $this->batch_ctrl, 'deploy' ) );
add_menu_page( 'Content Staging', 'Content Staging', 'manage_options', 'sme-list-batches', array( $this->batch_ctrl, 'list_batches' ) );
add_submenu_page( 'sme-list-batches', 'History', 'History', 'manage_options', 'sme-batch-history', array( $this->batch_history_ctrl, 'init' ) );
add_submenu_page( 'sme-list-batches', 'Settings', 'Settings', 'manage_options', 'sme-settings', array( $this->settings_ctrl, 'init' ) );
add_submenu_page( 'sme-list-batches', 'WordPress Options', 'WordPress Options', 'manage_options', 'sme-wp-options', array( $this->options_ctrl, 'init' ) );
add_submenu_page( null, 'Edit Batch', 'Edit', 'manage_options', 'sme-edit-batch', array( $this->batch_ctrl, 'edit_batch' ) );
add_submenu_page( null, 'Delete Batch', 'Delete', 'manage_options', 'sme-delete-batch', array( $this->batch_ctrl, 'confirm_delete_batch' ) );
add_submenu_page( null, 'Pre-Flight Batch', 'Pre-Flight', 'manage_options', 'sme-preflight-batch', array( $this->batch_ctrl, 'prepare' ) );
add_submenu_page( null, 'Quick Deploy Batch', 'Quick Deploy', 'manage_options', 'sme-quick-deploy-batch', array( $this->batch_ctrl, 'quick_deploy' ) );
add_submenu_page( null, 'Deploy Batch', 'Deploy', 'manage_options', 'sme-send-batch', array( $this->batch_ctrl, 'deploy' ) );
}

/**
* Display a "Deploy To Production" button whenever a post is updated.
*/

public function quick_deploy_batch( $messages ) {
global $post;

$post_ID = $post->ID;
$post_type = get_post_type( $post_ID );

$obj = get_post_type_object( $post_type );
$singular = $obj->labels->singular_name;

foreach ( $messages[$post_type] as $key => $message ) {
$messages[$post_type][$key] = $message . ' or <a href="' . admin_url( 'admin-post.php?action=sme-quick-deploy-batch&post_id=' . $_GET['post'] ) . '">Deploy To Production</a>';
public function quick_deploy_batch() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding my note in the PR, this seems to revert #81

if ( isset( $_GET['post'] ) && isset( $_GET['action'] ) && isset( $_GET['message'] ) && $_GET['action'] == 'edit' ) {
?>
<div class="updated">
<p><?php echo '<a href="' . admin_url( 'admin-post.php?action=sme-quick-deploy-batch&post_id=' . $_GET['post'] ) . '">Deploy To Production</a>'; ?></p>
</div>
<?php
}

return $messages;
}

/**
Expand All @@ -126,11 +119,19 @@ public function register_xmlrpc_methods( $methods ) {
}

public function set_postmeta_post_relation_keys( $meta_keys ) {
if ( ! in_array( '_thumbnail_id', $meta_keys ) ) {
$meta_keys[] = '_thumbnail_id';

$rel_keys = array(
'_thumbnail_id',
'_menu_item_menu_item_parent',
);

foreach ( $rel_keys as $key ) {
if ( ! in_array( $key, $meta_keys ) ) {
$meta_keys[] = $key;
}
}

return $meta_keys;
}

}
}
38 changes: 36 additions & 2 deletions classes/controllers/class-batch-ctrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use Me\Stenberg\Content\Staging\DB\Batch_DAO;
use Me\Stenberg\Content\Staging\DB\Post_DAO;
use Me\Stenberg\Content\Staging\Factories\DAO_Factory;
use Me\Stenberg\Content\Staging\Helper_Factory;
use Me\Stenberg\Content\Staging\Importers\Batch_Importer_Factory;
use Me\Stenberg\Content\Staging\Managers\Batch_Mgr;
use Me\Stenberg\Content\Staging\Models\Batch;
use Me\Stenberg\Content\Staging\Models\Message;
use Me\Stenberg\Content\Staging\View\Batch_Table;
use Me\Stenberg\Content\Staging\View\Post_Table;
use Me\Stenberg\Content\Staging\View\Template;
use Me\Stenberg\Content\Staging\XMLRPC\Client;
use SonyMobile\Content\Staging\View\Menu_Table;

class Batch_Ctrl {

Expand Down Expand Up @@ -198,6 +197,8 @@ public function edit_batch() {
);
$table->prepare_items();

$menu_table = $this->get_menu_table( $batch );

$type = get_post_type_object( 'sme_content_batch' );
if ( ! $batch->get_id() ) {
$label = $type->labels->new_item;
Expand All @@ -216,6 +217,7 @@ public function edit_batch() {
'label' => $label,
'filters' => $filters,
'table' => $table,
'menu_table' => $menu_table,
'post_ids' => implode( ',', $post_ids ),
'wp_options' => $wp_options,
);
Expand Down Expand Up @@ -852,6 +854,8 @@ private function handle_edit_batch_form_data( Batch $batch, $request_data ) {
$selected_post_ids = array_map( 'intval', explode( ',', $request_data['post_ids'] ) );
}

$this->save_selected_menus( $batch, $request_data );

// Set whether WordPress options should be included in batch or not.
$this->should_include_wp_options( $batch, $request_data );

Expand Down Expand Up @@ -965,4 +969,34 @@ private function verify_by_type( Batch $batch, $type ) {
}
}

private function get_menu_table( Batch $batch ) {

$menus = wp_get_nav_menus();
$selected = get_post_meta( $batch->get_id(), '_sme_selected_menus', true );

if ( ! is_array( $selected ) ) {
$selected = array();
}

$table = new Menu_Table( $selected );
$table->items = $menus;

$table->prepare_items();

return $table;
}

private function save_selected_menus( Batch $batch, array $request_data ) {

// IDs of menus user has selected to include in this batch.
$selected_menu_ids = array();

// Check if any menus to include in batch has been selected.
if ( isset( $request_data['menus'] ) && $request_data['menus'] ) {
$selected_menu_ids = array_map( 'intval', $request_data['menus'] );
}

update_post_meta( $batch->get_id(), '_sme_selected_menus', $selected_menu_ids );
}

}
15 changes: 15 additions & 0 deletions classes/controllers/class-options-ctrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ private function get_blacklist( $options ) {
return array_diff_key( $options, array_flip( $blacklist ) );
}

/**
* Options that should not be possible to sync to production.
*
* @return array
*/
private function get_default_blacklist() {
return array(
'siteurl',
'home',
'fileupload_url',
'sme_wp_options',
'rewrite_rules',
);
}

/**
* Options as presented in the view. Includes presentation specific data
* such as table row classes, input values etc.
Expand Down
64 changes: 56 additions & 8 deletions classes/db/class-option-dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,72 @@ public function get_option_names_to_sync() {
}

/**
* Insert options.
* Get options by pattern.
*
* Using the WordPress method 'update_option()' to insert/update options
* one by one.
*
* @todo Consider changing the implementation so that all options are
* imported in one query.
* @param string $pattern
* @return array
*/
public function get_option_names_by_pattern( $pattern ) {

$options = array();
$stmt = 'SELECT option_name FROM ' . $this->get_table() . ' WHERE option_name LIKE %s';
$query = $this->wpdb->prepare( $stmt, $pattern );
$result = $this->wpdb->get_results( $query, ARRAY_A );

foreach ( $result as $option ) {
$options[] = $option['option_name'];
}

return $options;
}

/**
* Update options.
*
* @param array $options
*/
public function insert_options( array $options ) {
public function update_options( array $options ) {
foreach ( $options as $option ) {
if ( $option instanceof Option ) {
update_option( $option->get_name(), $option->get_value(), $option->get_autoload() );
$old_value = get_option( $option->get_name() );

if ( $old_value === false ) {
$this->insert( $option );
} else {
$this->do_update( $option );
}
}
}
}

/**
* Update option. Create option if it does not already exist.
*
* @param Option $option
*/
public function update_option( Option $option) {
$old_value = get_option( $option->get_name() );

if ( $old_value === false ) {
$this->insert( $option );
} else {
$this->do_update( $option );
}
}

/**
* Update option.
*
* @param Option $option
*/
public function do_update( Option $option ) {
$data = $this->create_array( $option );
$where = array( 'option_name' => $option->get_name() );
$format = $this->format();
$where_format = array( '%s' );
$this->update( $data, $where, $format, $where_format );
}

/**
* @return string
*/
Expand Down
44 changes: 36 additions & 8 deletions classes/db/class-post-dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function get_posts( $statuses = array(), $order_by = null, $order = 'asc'
$nbr_of_selected = count( $selected );
$limit = $per_page;
$values = array();
$where = array();

if ( ( $offset = ( ( $paged - 1 ) * $per_page ) - $nbr_of_selected ) < 0 ) {
$offset = 0;
Expand All @@ -152,18 +153,36 @@ public function get_posts( $statuses = array(), $order_by = null, $order = 'asc'
$order = 'desc';
}

$where = 'post_type != "sme_content_batch" AND post_type != "sme_batch_import_job"';
$where = $this->where_statuses( $where, $statuses, $values );
$where = apply_filters( 'sme_query_posts_where', $where );
$values = apply_filters( 'sme_values_posts_where', $values );
$stmt = 'SELECT * FROM ' . $this->wpdb->posts . ' WHERE ' . $where;
// Post type.
$blacklisted_post_types = $this->get_blacklisted_post_types();

if ( ( $nbr_of_blacklisted_post_types = count( $blacklisted_post_types ) ) > 0 ) {
$blacklist_placeholders = implode( ',', array_fill( 0, $nbr_of_blacklisted_post_types, '%s' ) );
$where[] = 'post_type NOT IN (' . $blacklist_placeholders . ')';
$values = array_merge( $values, $blacklisted_post_types );
}

// Post status.
if ( ( $nbr_of_post_statuses = count( $statuses ) ) > 0 ) {
$post_status_placeholders = implode( ',', array_fill( 0, $nbr_of_post_statuses, '%s' ) );
$where[] = 'post_status IN (' . $post_status_placeholders . ')';
$values = array_merge( $values, $statuses );
}

// Post ID.
if ( ( $nbr_of_selected = count( $selected ) ) > 0 ) {
$placeholders = implode( ',', array_fill( 0, $nbr_of_selected, '%d' ) );
$values = array_merge( $values, $selected );
$stmt .= ' AND ID NOT IN (' . $placeholders . ')';
$id_placeholders = implode( ',', array_fill( 0, $nbr_of_selected, '%d' ) );
$where[] = 'ID NOT IN (' . $id_placeholders . ')';
$values = array_merge( $values, $selected );
}

// Implode where clauses into single where clause.
$where_clause = implode( ' AND ', $where );

$where_clause = apply_filters( 'sme_query_posts_where', $where_clause );
$values = apply_filters( 'sme_values_posts_where', $values );
$stmt = 'SELECT * FROM ' . $this->wpdb->posts . ' WHERE ' . $where_clause;

if ( ! is_null( $order_by ) ) {
$stmt .= ' ORDER BY ' . $order_by . ' ' . $order;
}
Expand Down Expand Up @@ -536,4 +555,13 @@ protected function format() {
);
}

private function get_blacklisted_post_types() {

$blacklist = array(
'sme_content_batch', 'sme_batch_import_job', 'nav_menu_item',
);

return apply_filters( 'sme_blacklisted_post_types', $blacklist );
}

}
Loading