Пример #1
0
 public function _registerCron($xml = NULL)
 {
     $this->parent->parent->debug($this::name_space . ': Registering cron jobs...');
     // Allows us to pump alternative xml into the function
     if ($xml === null) {
         $jobs = $this->module->getElementsByTagName('cron');
     } else {
         $jobs = $xml->getElementsByTagName('cron');
     }
     // Get the module ID so we can workout the group numbers
     $fetch_query = $this->mySQL_r->prepare("SELECT `module_id` FROM `core_modules` WHERE `namespace`=?");
     if ($fetch_query === false) {
         $this->parent->parent->debug($this::name_space . ': Fetch query failed!');
         return new ActionResult($this, '/admin/modules/install/', 0, 'Failed to register cron jobs!', B_T_FAIL, array('status' => 0, 'msg' => 'Failed to register cron jobs!'));
     }
     // Create the register query
     $register_query = $this->mySQL_w->prepare("INSERT INTO `core_cron`\n\t\t\t(`mins`,\t`hours`,\t`days`,\t`month`,\t`dow`, \t`user_id`,\t`mod_id`,\t`action`,\t`description`) VALUES\n\t\t\t(?,\t\t\t?,\t\t\t?,\t\t?,\t\t\t?,\t\t-1,\t\t\t?,\t\t\t?,\t\t\t?)\n\t\t");
     if ($register_query === false) {
         $this->parent->parent->debug($this::name_space . ': Cron job register query failed!');
         return new ActionResult($this, '/admin/modules/install/', 0, 'Failed to register cron jobs!', B_T_FAIL, array('status' => 0, 'msg' => 'Failed to register cron jobs!'));
     }
     // Get the module ID
     $fetch_query->bind_param('s', $this->namespace);
     $fetch_query->bind_result($MOD_ID);
     $fetch_query->execute();
     $fetch_query->store_result();
     if ($fetch_query->num_rows != 1) {
         $this->parent->parent->debug($this::name_space . ': Module isnt\'t registered!');
         return new ActionResult($this, '/admin/modules/install/', 0, 'Failed to register cron jobs!', B_T_FAIL, array('status' => 0, 'msg' => 'Failed to register cron jobs!'));
     }
     while ($fetch_query->fetch()) {
         $results = array();
         // Check we have some groups to register
         if ($jobs->length > 0) {
             $results[] = true;
         }
         // Loop throught the groups and register them
         foreach ($jobs as $job) {
             // Get the group details
             foreach (array('mins', 'hours', 'days', 'month', 'dow') as $var) {
                 // Fetch the tag value
                 ${$var} = XMLCut::fetchTagValue($job, $var);
                 // Set it to NULL if it is *
                 if (${$var} == '*') {
                     ${$var} = NULL;
                 }
                 $this->parent->parent->debug($this::name_space . ': Module ' . ucfirst($var) . ': "' . ${$var} . '"');
             }
             $action = XMLCut::fetchTagValue($job, 'action');
             $desc = XMLCut::fetchTagValue($job, 'description');
             $desc = $desc === NULL ? '' : $desc;
             // Bind the params
             $register_query->bind_param('iiiiiiss', $mins, $hours, $days, $month, $dow, $MOD_ID, $action, $desc);
             // Execute the query
             $register_query->execute();
             $register_query->store_result();
             // Dump the result into an array
             if ($register_query->affected_rows == 1) {
                 $this->parent->parent->debug($this::name_space . ': Registered job!');
                 $results[] = true;
             } else {
                 $this->parent->parent->debug($this::name_space . ': Failed to register job!');
                 $this->parent->parent->debug($this->mySQL_w->error);
                 $results[] = false;
             }
         }
         // Now we should have no false values if everything went well
         if (array_search(false, $results) !== true) {
             return new ActionResult($this, '/admin/modules/install/', 0, 'Processing module installer...', B_T_FAIL, array('status' => 1, 'msg' => 'Processing module installer...'));
         } else {
             $this->parent->parent->debug($this::name_space . ': Failed to register cron jobs!');
         }
     }
     // while($fetch_query->fetch())
 }
Пример #2
0
 /**
  * Updater::_updateModule()
  * 
  * @return
  */
 private function _updateModule()
 {
     $this->parent->parent->debug($this::name_space . ': Updating module registration...');
     // Get the core details
     $core = $this->module->getElementsByTagName('core')->item(0);
     // Loop throught the new data saved 20 lines of code. No really, I had one of the foreach
     // block code for each of the variables :/
     foreach (array('name', 'version', 'author', 'authorUrl', 'description', 'copyright') as $var) {
         ${$var} = XMLCut::fetchTagValue($core, $var);
         if (${$var} === null) {
             ${$var} = '';
         }
         $this->parent->parent->debug($this::name_space . ': Module ' . ucfirst($var) . ': "' . ${$var} . '"');
     }
     // Do the same for the boolean variables
     foreach (array('backup', 'uninstall') as $var) {
         ${$var} = XMLCut::fetchTagValue($this->module, $var);
         ${$var} = ${$var} !== '' ? 1 : 0;
         $this->parent->parent->debug($this::name_space . ': Module ' . ucfirst($var) . ': "' . ${$var} . '"');
     }
     // Update the database
     $update_query = $this->mySQL_w->prepare("UPDATE `core_modules` SET\n\t\t\t`name`=?, `version`=?, `description`=?, `author`=?, `authorUrl`=?, `copyright`=?, `backup`=?, `uninstall`=?\n\t\t\tWHERE `namespace`=?");
     // Check the that I didn't make a mistake in the query
     if ($update_query !== false) {
         $update_query->bind_param('ssssssiis', $name, $version, $description, $author, $authorUrl, $copyright, $backup, $uninstall, $this->module_ns);
         $update_query->execute();
         // Return success as the update will happen and we don't need to check for how many rows were affected
         return new ActionResult($this, '/admin/modules/install/', 0, 'Updating files...', B_T_SUCCESS, array('step' => 5, 'status' => 1, 'msg' => 'Updating pages...'));
     } else {
         $this->parent->parent->debug($this::name_space . ': Register query failed!');
     }
     // Return failed to update registration
     return new ActionResult($this, '/admin/modules/update/', 0, 'Failed to update module registration!', B_T_FAIL, array('status' => 0, 'msg' => 'Failed to update module registration!'));
 }