This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 
<?php defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Controller_Dashboard_System_Optimization_Jobs extends DashboardBaseController {

    function on_start() {
        parent::on_start();
        $this->set('availableJobs', Job::getAvailableList(0)); 
        $this->set('installedJobs', Job::getList()); 
        $this->set('jobSets', JobSet::getList());
        $this->set('auth', Job::generateAuth());
    }

    public function view() {
        $this->set('jobListSelected', true);
    }
    
    public function view_sets() {
        $this->set('jobSetsSelected', true);
    }

    function install($handle = null) {
        if ($handle) {
            Loader::model("job");
            Job::installByHandle($handle);
            $this->redirect('/dashboard/system/optimization/jobs', 'job_installed');
        } else {
            $this->error->add(t('No job specified.'));
        }
        $this->view();
    }
    
    function uninstall($job_id = null) {
        if ($job_id) {
            Loader::model("job");
            $job = Job::getByID((int) $job_id);
            if ($job) {
                if (!$job->jNotUninstallable) {
                    $job->uninstall();
                    $this->redirect('/dashboard/system/optimization/jobs', 'job_uninstalled');
                } else {
                    $this->error->add(t('This job cannot be uninstalled.'));
                }
            } else {
                $this->error->add(t('Job not found.'));
            }
        } else {
            $this->error->add(t('No job specified.'));
        }
        $this->view();
    }

    public function job_uninstalled() {
        $this->set('message', t('Job successfully uninstalled.'));
        $this->view();
    }

    public function job_installed() {
        $this->set('message', t('Job successfully installed.'));
        $this->view();
    }
    
    public function reset() {
        $jobs = Job::getList();
        foreach($jobs as $j) {
            $j->reset();
        }
        $this->redirect('/dashboard/system/optimization/jobs', 'reset_complete');
    }

    public function reset_complete() {
        $this->set('message', t('All running jobs have been reset.'));
        $this->view();
    }

    public function set_added() {
        $this->set('success', t('Job set added.'));
        $this->set('jobSetsSelected', true);
    }

    public function edit_set($jsID = false) {
        $this->set('jobSetsSelected', true);
        $js = JobSet::getByID($jsID);
        if (is_object($js)) {
            $this->set('set', $js);
        } else {
            $this->redirect('/dashboard/system/optimization/jobs');
        }
    }

    public function update_set_jobs() {
        if ($this->token->validate('update_set_jobs')) { 
            $js = JobSet::getByID($this->post('jsID'));
            if (!is_object($js)) {
                $this->error->add(t('Invalid Job set.'));
            }

            if (!$this->error->has()) {
                // go through and add all the attributes that aren't in another set
                $js->clearJobs();
                if (is_array($this->post('jID'))) {
                    foreach($_POST['jID'] as $jID) {
                        $j = Job::getByID($jID);
                        if(is_object($j)) {
                            $js->addJob($j);
                        }
                    }                   
                }
                $this->redirect('/dashboard/system/optimization/jobs', 'set_updated');
            }   
            
        } else {
            $this->error->add($this->token->getErrorMessage());
        }
        $this->edit($this->post('asID'));
    }
    public function set_updated() {
        $this->set('jobSetsSelected', true);
        $this->set('success', t('Job Set updated successfully.'));
    }

    public function update_set() {
        $this->set('jobSetsSelected', true);
        if ($this->token->validate('update_set')) { 
            $js = JobSet::getByID($this->post('jsID'));
            if (!is_object($js)) {
                $this->error->add(t('Invalid Job set.'));
            } else {
                if (!trim($this->post('jsName'))) { 
                    $this->error->add(t("Specify a name for your Job set."));
                }
            }
            
            if (!$this->error->has()) {
                $js->updateJobSetName($this->post('jsName'));
                $this->redirect('/dashboard/system/optimization/jobs', 'set_updated');
            }
            
        } else {
            $this->error->add($this->token->getErrorMessage());
        }
    }

    public function set_deleted() {
        $this->set('jobSetsSelected', true);
        $this->set('success', t('Group set deleted successfully.'));
    }

    public function delete_set() {
        $this->set('jobSetsSelected', true);
        if ($this->token->validate('delete_set')) { 
            $js = JobSet::getByID($this->post('jsID'));
            if (!$js->canDelete()) {
                $this->error->add(t('You cannot delete the default Job set.'));
            }

            if (!is_object($js)) {
                $this->error->add(t('Invalid Job set.'));
            }
            if (!$this->error->has()) {
                $js->delete();
                $this->redirect('/dashboard/system/optimization/jobs', 'set_deleted');
            }           
            $this->edit_set($this->post('jsID'));
        } else {
            $this->error->add($this->token->getErrorMessage());
        }
    }

    public function add_set() {
        $this->set('jobSetsSelected', true);
        if ($this->token->validate('add_set')) { 
            if (!trim($this->post('jsName'))) { 
                $this->error->add(t("Specify a name for your Job set."));
            }
            if (!$this->error->has()) {         
                $js = JobSet::add($this->post('jsName'));
                if (is_array($_POST['jID'])) {
                    foreach($_POST['jID'] as $jID) {
                        $j = Job::getByID($jID);
                        if(is_object($j)) {
                            $js->addJob($j);
                        }
                    }                   
                }
                $this->redirect('/dashboard/system/optimization/jobs', 'set_added');
            }
            
        } else {
            $this->error->add($this->token->getErrorMessage());
        }
    }

    public function update_job_schedule() {
        $jID = $this->post('jID');
        $J = Job::getByID($jID);
        $J->setSchedule($this->post('isScheduled'), $this->post('unit'), max(0,(int)$this->post('value')));
        
        $this->redirect('/dashboard/system/optimization/jobs', 'job_scheduled');
    }
    
    public function job_scheduled() {
        $this->set('success', t('Job schedule updated successfully.'));
        $this->view();
    }
    
    
    public function update_set_schedule() {
        $jsID = $this->post('jsID');
        $S = JobSet::getByID($jsID);
        $S->setSchedule($this->post('isScheduled'), $this->post('unit'), $this->post('value'));
        
        $this->redirect('/dashboard/system/optimization/jobs', 'set_scheduled');
    }
    
    public function set_scheduled() {
        $this->set('success', t('Job Set schedule updated successfully.'));
        $this->view();
    }
    
    
}