/** * The business method if this page is called from the commmand line * @param array $request_remainder the remainder of the request after the page specfication. * @param array $args the array of unix style command line arguments * Arguements are link that in: http://us3.php.net/manual/en/features.commandline.php#78651 * If we were called as: * index.php --page=/module/page/some/thing/else --long -AB 2 -C -D 'ostrich' --eggs==good * Then $request_remainder = array('some','thing','else') * and $args = array('long'=>true, 'A'=>true, 'B'=>2, 'C'=>true, 'D'=>'ostrich', 'eggs'=>'good') */ protected function actionCommandLine($args, $request_remainder) { if (count($this->request_remainder) == 0) { if ($this->page == 'cacheAll') { $this->cacheAll(true); } else { if ($this->page == 'cacheAllForce') { $this->cacheAll(false); } else { if ($this->page == 'dropAll') { $this->dropAll(); } else { if ($this->page == 'cache' && count($selected = $this->getSelected()) > 0) { return $this->cacheAll(true, $selected); } else { if ($this->page == 'cacheForce' && count($selected = $this->getSelected()) > 0) { return $this->cacheAll(false, $selected); } else { if ($this->page == 'dropAndCache' && count($selected = $this->getSelected()) > 0) { $this->dropAll($selected); return $this->cacheAll(true, $selected); } else { if ($this->page == 'dropAndCacheForce' && count($selected = $this->getSelected()) > 0) { $this->dropAll($selected); return $this->cacheAll(false, $selected); } else { I2CE::raiseError("No action specfied"); } } } } } } } return true; } else { $form = $this->request_remainder[0]; $id = null; if (array_key_exists(1, $this->request_remainder)) { $id = $this->request_remainder[1]; } try { $cachedForm = new I2CE_CachedForm($form); } catch (Exception $e) { $this->addTextMessage("Unable to setup cached form {$form}"); return false; } $msg = ''; switch ($this->page) { case 'createCache': if ($id === null) { if ($cachedForm->generateCachedTable(true, true)) { $msg = "Cached Table for {$form} generated"; } else { $msg = "Cached Table for {$form} not generated"; } } else { if ($cachedForm->updateCachedTable($id, true)) { $msg = "Cached Table for {$form} {$id} updated"; } else { $msg = "Cached Table for {$form} {$id} not updated"; } } break; case 'forceCreateCache': if ($id === null) { if ($cachedForm->generateCachedTable(false, false)) { $msg = "Cached Table for {$form} generated (forced)"; } else { $msg = "Cached Table for {$form} not generated (forced)"; } } else { if ($cachedForm->updateCachedTable($id)) { $msg = "Cached Table for {$form} {$id} updated (forced)"; } else { $msg = "Cached Table for {$form} {$id} not updated (forced)"; } } break; case 'dropCache': if ($cachedForm->dropTable()) { $msg = "Cached Table for {$form} dropped"; } else { $msg = "Cached Table for {$form} not dropped"; } break; default: $msg = "No action specifed for {$form}. The valid actions are 'createCache', 'forceCreateCache', and 'dropCache'"; break; } I2CE::raiseError($msg); return true; } }
/** * Hooked method to marks a form as dirty (needs to be cached). * @param mixed $args. an array of two elements whose first element is a form object, the second is the user */ public function markFormDirty_hook($args) { if (!is_array($args) || !array_key_exists('form', $args)) { return; } $form = $args['form']; if (!$form instanceof I2CE_Form) { return; } $form_name = $form->getName(); try { $cache = new I2CE_CachedForm($form_name); if (!$cache->updateCachedTable($form->getID())) { self::markFormDirty($form_name); } } catch (Exception $e) { self::markFormDirty($form_name); } }