/**
  * A convenience wrapper to assign the cancelled subscriber role to a user.
  *
  * Hooked to 'subscription_end_of_prepaid_term' hook.
  *
  * @param int $user_id The id of the user whose role should be changed
  * @since 1.3.2
  * @deprecated 2.0
  */
 public static function maybe_assign_user_cancelled_role($user_id)
 {
     _deprecated_function(__METHOD__, '2.0', 'wcs_maybe_make_user_inactive()');
     wcs_maybe_make_user_inactive($user_id);
 }
 /**
  * Updates status of the subscription
  *
  * @param string $new_status Status to change the order to. No internal wc- prefix is required.
  * @param string $note (default: '') Optional note to add
  */
 public function update_status($new_status, $note = '', $manual = false)
 {
     if (!$this->id) {
         return;
     }
     // Standardise status names.
     $new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
     $new_status_key = 'wc-' . $new_status;
     $old_status = $this->get_status();
     $old_status_key = $this->post_status;
     if ($new_status !== $old_status || !in_array($this->post_status, array_keys(wcs_get_subscription_statuses()))) {
         // Only update is possible
         if (!$this->can_be_updated_to($new_status)) {
             $message = sprintf(__('Unable to change subscription status to "%s".', 'woocommerce-subscriptions'), $new_status);
             $this->add_order_note($message);
             do_action('woocommerce_subscription_unable_to_update_status', $this, $new_status, $old_status);
             // Let plugins handle it if they tried to change to an invalid status
             throw new Exception($message);
         }
         try {
             wp_update_post(array('ID' => $this->id, 'post_status' => $new_status_key));
             $this->post_status = $new_status_key;
             switch ($new_status) {
                 case 'pending':
                     // Nothing to do here
                     break;
                 case 'pending-cancel':
                     $end_date = $this->calculate_date('end_of_prepaid_term');
                     // If there is no future payment and no expiration date set, the customer has no prepaid term (this shouldn't be possible as only active subscriptions can be set to pending cancellation and an active subscription always has either an end date or next payment)
                     if (0 == $end_date) {
                         $end_date = current_time('mysql', true);
                     }
                     $this->delete_date('trial_end');
                     $this->delete_date('next_payment');
                     $this->update_dates(array('end' => $end_date));
                     break;
                 case 'completed':
                     // core WC order status mapped internally to avoid exceptions
                 // core WC order status mapped internally to avoid exceptions
                 case 'active':
                     // Recalculate and set next payment date
                     $next_payment = $this->get_time('next_payment');
                     if ($next_payment < gmdate('U')) {
                         // also accounts for a $next_payment of 0, meaning it's not set
                         $next_payment = $this->calculate_date('next_payment');
                         if ($next_payment > 0) {
                             $this->update_dates(array('next_payment' => $next_payment));
                         }
                     }
                     // Trial end date and end/expiration date don't change at all - they should be set when the subscription is first created
                     wcs_make_user_active($this->customer_user);
                     break;
                 case 'failed':
                     // core WC order status mapped internally to avoid exceptions
                 // core WC order status mapped internally to avoid exceptions
                 case 'on-hold':
                     // Record date of suspension - 'post_modified' column?
                     $this->update_suspension_count($this->suspension_count + 1);
                     wcs_maybe_make_user_inactive($this->customer_user);
                     break;
                 case 'cancelled':
                 case 'switched':
                 case 'expired':
                     $this->delete_date('trial_end');
                     $this->delete_date('next_payment');
                     $this->update_dates(array('end' => current_time('mysql', true)));
                     wcs_maybe_make_user_inactive($this->customer_user);
                     break;
             }
             $this->add_order_note(trim($note . ' ' . sprintf(__('Status changed from %s to %s.', 'woocommerce-subscriptions'), wcs_get_subscription_status_name($old_status), wcs_get_subscription_status_name($new_status))), 0, $manual);
             // dynamic hooks for convenience
             do_action('woocommerce_subscription_status_' . $new_status, $this);
             do_action('woocommerce_subscription_status_' . $old_status . '_to_' . $new_status, $this);
             // Trigger a hook with params we want
             do_action('woocommerce_subscription_status_updated', $this, $new_status, $old_status);
             // Trigger a hook with params matching WooCommerce's 'woocommerce_order_status_changed' hook so functions attached to it can be attached easily to subscription status changes
             do_action('woocommerce_subscription_status_changed', $this->id, $old_status, $new_status);
         } catch (Exception $e) {
             // Make sure the old status is restored
             wp_update_post(array('ID' => $this->id, 'post_status' => $old_status_key));
             $this->post_status = $old_status_key;
             $this->add_order_note(sprintf(__('Unable to change subscription status to "%s".', 'woocommerce-subscriptions'), $new_status));
             do_action('woocommerce_subscription_unable_to_update_status', $this, $new_status, $old_status);
             throw $e;
         }
     }
 }