/**
  * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message accordingly.
  *
  * @access public
  * @throws EE_Error
  * @return void
  */
 public function verify_cpt_object()
 {
     $label = !empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
     // verify event object
     if (!$this->_cpt_model_obj instanceof EE_CPT_Base) {
         throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page', 'event_espresso'), $label));
     }
     //if auto-draft then throw an error
     if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
         EE_Error::overwrite_errors();
         EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), $label), __FILE__, __FUNCTION__, __LINE__);
     }
 }
 function _migration_step($num_items = 50)
 {
     $items_actually_migrated = 0;
     $old_org_options = get_option('events_organization_settings');
     foreach ($this->_org_options_we_know_how_to_migrate as $option_name) {
         //only bother migrating if there's a setting to migrate. Otherwise we'll just use the default
         if (isset($old_org_options[$option_name])) {
             $this->_handle_org_option($option_name, $old_org_options[$option_name]);
         }
         if ($option_name == 'surcharge') {
             $this->_insert_new_global_surcharge_price($old_org_options);
         }
         $items_actually_migrated++;
     }
     $success = EE_Config::instance()->update_espresso_config(FALSE, TRUE);
     if (!$success) {
         $this->add_error(sprintf(__('Could not save EE Config during org options stage. Reason: %s', 'event_espresso'), EE_Error::get_notices(FALSE)));
         EE_Error::overwrite_errors();
     }
     EE_Network_Config::instance()->update_config(FALSE, FALSE);
     if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
         //we may have added new pages and this might be necessary
         flush_rewrite_rules();
         $this->set_completed();
     }
     return $items_actually_migrated;
 }
    /**
     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
     * EEM_Message::status_idle
     *
     * @since 4.9.0
     * @param $message_ids
     *
     * @return bool | EE_Messages_Queue  false if no messages sent.
     */
    public static function send_now($message_ids)
    {
        self::_load_controller();
        $messages = EEM_Message::instance()->get_all(array(0 => array('MSG_ID' => array('IN', $message_ids), 'STS_ID' => array('IN', array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry)))));
        $sent_queue = false;
        if ($messages) {
            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
        }
        if (!$sent_queue instanceof EE_Messages_Queue) {
            EE_Error::add_error(__('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
        } else {
            //can count how many sent by using the messages in the queue
            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
            if ($sent_count > 0) {
                EE_Error::add_success(sprintf(_n('There was %d message successfully sent.', 'There were %d messages successfully sent.', $sent_count, 'event_espresso'), $sent_count));
            } else {
                EE_Error::overwrite_errors();
                EE_Error::add_error(__('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
					If there was an error, you can look at the messages in the message activity list table for any error messages.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
            }
        }
        return $sent_queue;
    }