protected function getReloadData() { $modx =& $this->modx; $scriptProperties =& $this->scriptProperties; $reloadData = array(); // get reload data if reload token found in registry if (array_key_exists('reload', $scriptProperties) && !empty($scriptProperties['reload'])) { if (!isset($modx->registry)) { $modx->getService('registry', 'registry.modRegistry'); } /** @var modRegistry $modx->registry */ if (isset($modx->registry)) { $modx->registry->addRegister('resource_reload', 'registry.modDbRegister', array('directory' => 'resource_reload')); $this->reg = $modx->registry->resource_reload; if ($this->reg->connect()) { $topic = '/resourcereload/' . $scriptProperties['reload']; $this->reg->subscribe($topic); $msgs = $this->reg->read(array('poll_limit' => 1, 'remove_read' => true)); if (is_array($msgs)) { $reloadData = reset($msgs); } if (!is_array($reloadData)) { $reloadData = array(); } $this->reg->unsubscribe($topic); } } } return $reloadData; }
/** * Construct a new modFileRegister instance. * * {@inheritdoc} */ function __construct(& $modx, $key, $options = array()) { parent :: __construct($modx, $key, $options); $modx->getCacheManager(); $this->directory = $modx->getCachePath() . 'registry/'; $this->directory .= isset($options['directory']) ? $options['directory'] : $key; if ($this->directory[strlen($this->directory)-1] != '/') $this->directory .= '/'; }
/** * Construct a new modDbRegister instance. * * @param modX &$modx A reference to the modX instance * @param string $key The key of the registry to load * @param array $options An array of options to set */ function __construct(modX &$modx, $key, array $options = array()) { parent::__construct($modx, $key, $options); $this->_queue = $this->_initQueue($key, $options); }
/** * Provides custom logging functionality for modRegister targets. * * @access protected * @param modRegister $register The modRegister instance to send to * @param int $level The level of error or message that occurred * @param string $msg The message to send to the register * @param string $def The type of error that occurred * @param string $file The filename of the file that the message occurs for * @param string $line The line number of the file that the message occurs for */ protected function _logInRegister($register, $level, $msg, $def, $file, $line) { $timestamp = strftime('%Y-%m-%d %H:%M:%S'); $messageKey = (string) time(); $messageKey .= '-' . sprintf("%06d", $this->_logSequence); $message = array('timestamp' => $timestamp, 'level' => $this->_getLogLevel($level), 'msg' => $msg, 'def' => $def, 'file' => $file, 'line' => $line); $options = array(); if ($level === xPDO::LOG_LEVEL_FATAL) { $options['kill'] = true; } $register->send('', array($messageKey => $message), $options); $this->_logSequence++; }
/** * Subscribe to register and read it * @return mixed */ public function readRegister() { $this->register->subscribe($this->topic); return $this->register->read($this->options); }
/** * Subscribe register and send message * @return bool */ public function sendMessage() { $options = array('delay' => (int) $this->getProperty('delay', 0), 'ttl' => (int) $this->getProperty('ttl', 0), 'kill' => (bool) $this->getProperty('kill', false)); $this->register->subscribe($this->topic); return $this->register->send($this->topic, $this->message, $options); }