/**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     // permission
     WCF::getUser()->checkPermission('admin.system.adminTools.canView');
     $this->atSettings = AdminTools::getSettings();
     foreach ($this->atSettings as $k => $val) {
         if (isset($this->{$k})) {
             $this->{$k} = $val;
         }
     }
     // execute cron job
     if (!empty($_REQUEST['cRun'])) {
         if ($_REQUEST['cRun'] == 'journal' && (isset($_REQUEST['log']) || isset($_REQUEST['stat']))) {
             AdminTools::cronRunJournal(0, isset($_REQUEST['log']) ? $_REQUEST['log'] : 0, isset($_REQUEST['stat']) ? $_REQUEST['stat'] : 0, isset($_REQUEST['adminMail']) ? $_REQUEST['adminMail'] : 0);
         } else {
             if ($_REQUEST['cRun'] == 'db' && (isset($_REQUEST['analyze']) || isset($_REQUEST['optimize']) || isset($_REQUEST['backup']))) {
                 AdminTools::cronRunDB(isset($_REQUEST['analyze']) ? $_REQUEST['analyze'] : 0, isset($_REQUEST['optimize']) ? $_REQUEST['optimize'] : 0, isset($_REQUEST['backup']) ? $_REQUEST['backup'] : 0);
             } else {
                 if ($_REQUEST['cRun'] == 'subscriptions') {
                     $cnt = AdminTools::cronCleanUpSubscriptions(false);
                     $this->subscriptionsMsg = WCF::getLanguage()->get('wcf.acp.adminTools.cron.cronCleanUpSubscriptions.cleaned', array('$cnt' => $cnt));
                 }
             }
         }
     }
 }
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     // read settings ***********************************
     $this->atSettings = AdminTools::getSettings();
     // check last execution time
     $this->atSettings['cronLastRun'] = intval($this->atSettings['cronLastRun']);
     if ($this->atSettings['cronLastRun'] < TIME_NOW - 3600) {
         $sql = "UPDATE wcf" . WCF_N . "_admin_tool_setting" . "\n   SET atse_value = '" . TIME_NOW . "'" . "\n WHERE atse_name = 'cronLastRun'";
         WCF::getDB()->sendQuery($sql);
     } else {
         return;
     }
     // WBB-LOG *****************************************
     if (!empty($this->atSettings['cronDelLogDays'])) {
         WCF::getDB()->sendQuery("DELETE FROM wcf" . WCF_N . "_cronjobs_log WHERE execTime < " . (time() - $this->atSettings['cronDelLogDays'] * 86400));
     }
     // delete PNs **************************************
     if (!empty($this->atSettings['cronDelPmDays'])) {
         $dPMs = $cnt = 0;
         $sql = "SELECT pmID" . "\n  FROM wcf" . WCF_N . "_pm" . "\n WHERE time < " . (time() - $this->atSettings['cronDelPmDays'] * 86400);
         if (!empty($this->atSettings['cronDelPmDaysExclUgrps'])) {
             $sql .= "\n   AND userID NOT IN (SELECT userID FROM wcf" . WCF_N . "_user_to_groups WHERE groupID IN (" . $this->atSettings['cronDelPmDaysExclUgrps'] . "))";
         }
         if (!empty($this->atSettings['cronDelPmDaysExclUser'])) {
             $sql .= "\n   AND userID NOT IN (" . $this->atSettings['cronDelPmDaysExclUser'] . ")";
         }
         if (!empty($this->atSettings['cronDelPmDaysExclFolder'])) {
             $sql .= "\n   AND pmID NOT IN (SELECT pmID FROM wcf" . WCF_N . "_pm_to_user WHERE folderID > 0)";
         }
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $cnt++;
             $this->pmDelCnt++;
             $dPMs .= ',' . $row['pmID'];
             if ($cnt % 50 == 0) {
                 AdminTools::deletePMs($dPMs);
                 $cnt = 0;
                 $dPMs = 0;
             }
         }
         if (!empty($dPMs)) {
             AdminTools::deletePMs($dPMs);
         }
     }
     // delete inactive user ****************************
     if (!empty($this->atSettings['cronDelInactiveUserDays']) && $this->atSettings['cronDelInactiveUserDays'] > 0) {
         AdminTools::deleteInactiveUser($this->atSettings['cronDelInactiveUserDays'], $this->atSettings['cronDelInactiveUserExcl'], $this->atSettings['cronDelInactiveUserExclUgrps']);
     }
     // check moved threads
     AdminTools::cronCheckMovedThreads(intval($this->atSettings['cronDelMovedThreadDays']));
     // archive
     AdminTools::cronThreadArchive($this->atSettings);
     // cleanup subscriptions
     if (!empty($this->atSettings['cronCleanUpSubscriptions'])) {
         AdminTools::cronCleanUpSubscriptions();
     }
     // spider ******************************************
     AdminTools::syncSpider();
     // journal *****************************************
     AdminTools::cronRunJournal($this->pmDelCnt, $this->atSettings['cronLogEnabled'], $this->atSettings['cronStatEnabled'], $this->atSettings['cronLogUseAdminEmail']);
     // DB **********************************************
     AdminTools::cronRunDB($this->atSettings['cronDbAnalyze'], $this->atSettings['cronDbOptimize'], $this->atSettings['cronDbBackup']);
 }