https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /var/www/laciasmara.com/public_html/shop/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/laciasmara.com/public_html/shop/application/models/Campaign_email_queue_m.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Campaign_email_queue_m extends MY_Model
{
    protected $table = 'campaign_email_queue';
    protected $fillable = array('campaign_id', 'subscriber_id', 'priority', 'attempts', 'max_attempts', 'status', 'scheduled_for', 'processed_at', 'error_message');

    /**
     * Add emails to queue
     */
    public function add_to_queue($campaign_id, $subscriber_ids, $priority = 1)
    {
        $queue_data = array();
        foreach ($subscriber_ids as $subscriber_id) {
            $queue_data[] = array(
                'campaign_id' => $campaign_id,
                'subscriber_id' => $subscriber_id,
                'priority' => $priority,
                'status' => 'pending'
            );
        }

        return $this->batch_insert($queue_data);
    }

    /**
     * Get next batch for processing
     */
    public function get_next_batch($limit = 50)
    {
        $this->db->select('eq.*, c.name as campaign_name, s.email, s.first_name, s.last_name');
        $this->db->from($this->table . ' eq');
        $this->db->join('campaigns c', 'eq.campaign_id = c.id');
        $this->db->join('subscribers s', 'eq.subscriber_id = s.id');
        $this->db->where('eq.status', 'pending');
        $this->db->where('eq.scheduled_for <=', date('Y-m-d H:i:s'));
        $this->db->where('eq.attempts <', 'eq.max_attempts', FALSE);
        $this->db->order_by('eq.priority', 'desc');
        $this->db->order_by('eq.created_at', 'asc');
        $this->db->limit($limit);

        $query = $this->db->get();
        return $query->result_array();
    }

    /**
     * Mark as processing
     */
    public function mark_processing($queue_ids)
    {
        $this->db->where_in('id', $queue_ids);
        return $this->db->update($this->table, array(
            'status' => 'processing',
            'processed_at' => date('Y-m-d H:i:s')
        ));
    }

    /**
     * Mark as completed
     */
    public function mark_completed($queue_id)
    {
        return $this->update($queue_id, array(
            'status' => 'completed',
            'processed_at' => date('Y-m-d H:i:s')
        ));
    }

    /**
     * Mark as failed
     */
    public function mark_failed($queue_id, $error_message)
    {
        $queue_item = $this->get_by_id($queue_id);
        $attempts = $queue_item['attempts'] + 1;

        $data = array(
            'attempts' => $attempts,
            'error_message' => $error_message,
            'processed_at' => date('Y-m-d H:i:s')
        );

        if ($attempts >= $queue_item['max_attempts']) {
            $data['status'] = 'failed';
        } else {
            $data['status'] = 'pending';
            // Reschedule for retry (15 minutes later)
            $data['scheduled_for'] = date('Y-m-d H:i:s', strtotime('+15 minutes'));
        }

        return $this->update($queue_id, $data);
    }
}

https://t.me/RX1948 - 2025