1

Users are able to submit an entry and it defaults to a status of 'Awaiting Moderation'. When our administrator reviews the entry and changes its status to 'Open', I would like to set the expiration date 60 days in the future.

In my extension, I've tried using the entry_submission_ready hook and the entry_submission_end hook, but I don't seem to be able to detect a difference in status.

public function set_expiration_date( $meta = array(), $data = array(), $auto_save = array() ) {

    $old_status = isset( $meta['status'] ) ? strtolower( $meta['status'] ) : '';
    $new_status = isset( $_POST['status'] ) ? strtolower( $_POST['status'] ) : '';

    if ( 'open' != $old_status && 'open' == $new_status && '14' == $data['channel_id'] && 'mydata' == $data['field_id_123'] ) {
        // set expiration date 60 days in the future
        $future = date('Y-m-d', time() + 60*24*60*60);
        $exp_time = strtotime(  $future . ' 23:59:59' );
        $data['expiration_date'] = $exp_time;
    } else {
        return;
    }
}

When using entry_submission_ready, $old_status and $new_status always seems to be the previous status. And with entry_submission_end, $old_status and $new_status are always the next status. So $_POST is changed.

I don't understand how to use this EE hook. What am I missing?

0

The extension hook entry_submission_ready is being called just prior to insertion / update so you should use this hook rather than entry_submission_end.

As you are calling this extension while an entry is being updated so you can get the Status of that entry using the SQL like:

$old_status = ee()->db->select('status')->where('entry_id', $data['entry_id'])->get('channel_titles')->row('status');

$new_status = $meta['status'];

You can do further processing as your code.

I hope, it would help you.

| improve this answer | |
  • Thanks, that helps me get a step closer. I know I can't change the $meta and $data arrays to change the expiration_date. But I tried $this->EE->api_channel_entries->data['revision_post']['expiration_date'] = $exp_time; but it didn't save the expiration date. – Jeff Wolfe Jul 18 '13 at 1:56
  • yes, you are correct ... – Bhashkar Yadav Jul 18 '13 at 2:04
  • That does not seem to work. I've tried $this->EE->api_channel_entries->data['revision_post']['expiration_date'] = $exp_time; and $this->EE->api_channel_entries->data['expiration_date'] = $exp_time; – Jeff Wolfe Jul 18 '13 at 2:39
  • Try $this->EE->api_channel_entries->meta['expiration_date'] = $exp_time;. Make sure that $exp_time would be in Unix timestamp. – Bhashkar Yadav Jul 18 '13 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.