Skip to content

Commit

Permalink
Fixed: If no _ap_updated meta then use post_date in last_updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularyan committed Jul 22, 2017
1 parent d0ac929 commit e09c5dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion anspress-question-answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private function includes() {

require_once ANSPRESS_DIR . 'lib/class-anspress-upgrader.php';

if ( class_exists( 'WP_CLI' ) ) {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once ANSPRESS_DIR . 'lib/class-anspress-cli.php';
}
}
Expand Down
17 changes: 17 additions & 0 deletions lib/class-anspress-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public function version() {
WP_CLI::success( 'Currently installed version of AnsPress is ' . AP_VERSION );
}

/**
* Upgrade AnsPress 3.x data to 4.x.
*
* Warning! This will delete/edit/rename lots of mysql rows and
* tables, so make sure to do a full backup before running this command.
*
* ## OPTIONS
*
* [--yes]
* : Passing this will not ask for backup confirm.
*
* ## EXAMPLES
*
* wp anspress upgrade --yes
*
* @when after_wp_load
*/
public function upgrade( $args, $assoc_args ) {
print( "=== Starting upgrade process ===\n\r" );

Expand Down
9 changes: 6 additions & 3 deletions lib/class-anspress-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function __construct() {

foreach ( (array) $this->question_ids as $id ) {
// Translators: Question ID in placeholder.
print( sprintf( __( 'Migrating question: %d', 'anspress-question-answer' ), $id ) );
print( "\n\r" . sprintf( __( 'Migrating question: %d', 'anspress-question-answer' ), $id ) . "\n\r" );
$this->question_tasks( $id );
}

Expand Down Expand Up @@ -133,6 +133,7 @@ private function question_tasks( $id ) {
'flags' => (int) get_post_meta( $id, '_ap_flag', true ),
'selected_id' => $answer_id,
'featured' => in_array( $id, $featured_questions ),
'last_updated' => empty( $last_active ) ? $question->post_date : $last_active,
) );

ap_update_qameta_terms( $id );
Expand Down Expand Up @@ -206,12 +207,14 @@ public function delete_question_metatables( $id ) {
* @return void
*/
private function answer_tasks( $answer_id ) {
$answer = get_post( $answer_id );
$last_active = get_post_meta( $answer_id, '_ap_updated', true );
$best_answer = get_post_meta( $answer_id, '_ap_best_answer', true );
$flags = (int) get_post_meta( $answer_id, '_ap_flag', true );

$args = array(
'flags' => $flags,
'flags' => $flags,
'last_updated' => empty( $last_active ) ? $answer->post_date : $last_active,
);

if ( '1' === $best_answer ) {
Expand Down Expand Up @@ -241,7 +244,7 @@ private function answer_tasks( $answer_id ) {
*/
public function restore_last_activity( $post_id ) {
$activity = get_post_meta( $post_id, '__ap_activity', true );
print_r( $activity );

// Restore last activity.
if ( ! empty( $activity ) ) {
ap_insert_qameta( $post_id, [ 'activities' => $activity ] );
Expand Down

0 comments on commit e09c5dd

Please sign in to comment.