/** * Loads all entries that need to be processed and processes them. */ public function _on_execute() { $qb = midcom_services_at_entry_dba::new_query_builder(); // (to be) start(ed) AND last touched over two days ago $qb->add_constraint('start', '<=', time() - 3600 * 24 * 2); $qb->begin_group('OR'); $qb->add_constraint('host', '=', midcom_connection::get('host')); $qb->add_constraint('host', '=', 0); $qb->end_group(); $qb->add_constraint('metadata.revised', '<=', date('Y-m-d H:i:s', time() - 3600 * 24 * 2)); $qb->add_constraint('status', '>=', midcom_services_at_entry_dba::RUNNING); midcom::get('auth')->request_sudo('midcom.services.at'); $qbret = $qb->execute(); if (empty($qbret)) { debug_add('Got empty resultset, exiting'); midcom::get('auth')->drop_sudo(); return; } foreach ($qbret as $entry) { debug_add("Deleting dangling entry #{$entry->id}\n", MIDCOM_LOG_INFO); debug_print_r("Entry #{$entry->id} dump: ", $entry); $entry->delete(); } midcom::get('auth')->drop_sudo(); }
/** * Makes sure we have status set and arguments serialized * * @return boolean Always true */ public function _on_creating() { if (!$this->status) { $this->status = self::SCHEDULED; } if (!$this->host) { $this->host = midcom_connection::get('host'); } $this->_serialize_arguments(); return true; }
/** * Static method for listing available style templates */ public static function list_styles($up = 0, $prefix = '/', $spacer = '') { static $style_array = array(); $style_array[''] = midcom::get('i18n')->get_string('default', 'midcom.admin.folder'); // Give an option for creating a new layout template $style_array['__create'] = midcom::get('i18n')->get_string('new layout template', 'midcom.admin.folder'); if ($GLOBALS['midcom_config']['styleengine_relative_paths'] && $up == 0) { // Relative paths in use, start seeking from under the style used for the Midgard host $up = midcom_connection::get('style'); } $qb = midcom_db_style::new_query_builder(); $qb->add_constraint('up', '=', $up); $styles = $qb->execute(); foreach ($styles as $style) { $style_string = "{$prefix}{$style->name}"; // Hide common unwanted material with heuristics if (preg_match('/(asgard|empty)/i', $style_string)) { continue; } $style_array[$style_string] = "{$spacer}{$style->name}"; self::list_styles($style->id, $style_string . '/', $spacer . ' '); } return $style_array; }
/** * Internal startup helper, synchronizes the authenticated user with the Midgard Authentication * for startup. This will be overridden by MidCOM Auth, but is there for compatibility reasons. */ private function _initialize_user_from_midgard() { if (midcom_connection::get_user() && ($user = $this->get_user(midcom_connection::get_user()))) { $this->user = $user; if (midcom_connection::is_admin() || midcom_connection::get('root')) { $this->admin = true; } } }
public function export() { $this->read_root(midcom_connection::get('style')); }
/** * Loads all entries that need to be processed and processes them. * * @todo FIXME: refactor to use more modern MidCOM interfaces and better sanity-checking */ public function _on_execute() { $qb = midcom_services_at_entry_dba::new_query_builder(); $qb->add_constraint('start', '<=', time()); $qb->begin_group('OR'); $qb->add_constraint('host', '=', midcom_connection::get('host')); $qb->add_constraint('host', '=', 0); $qb->end_group(); $qb->add_constraint('status', '=', midcom_services_at_entry_dba::SCHEDULED); $qb->set_limit((int) $this->_config->get('limit_per_run')); midcom::get('auth')->request_sudo('midcom.services.at'); $qbret = $qb->execute(); midcom::get('auth')->drop_sudo(); if (empty($qbret)) { debug_add('Got empty resultset, exiting'); return; } foreach ($qbret as $entry) { debug_add("Processing entry #{$entry->id}\n"); //Avoid double-execute in case of long runs $entry->status = midcom_services_at_entry_dba::RUNNING; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); midcom::get('componentloader')->load($entry->component); $args = $entry->arguments; $args['midcom_services_at_entry_object'] = $entry; $interface = midcom::get('componentloader')->get_interface_class($entry->component); $method = $entry->method; if (!is_callable(array($interface, $method))) { $error = "\$interface->{$method}() is not callable"; $this->print_error($error); debug_add($error, MIDCOM_LOG_ERROR); debug_add('$interface is ' . get_class($interface)); debug_print_r('$args', $args); //PONDER: Delete instead ? (There is currently nothing we do with failed entries) $entry->status = midcom_services_at_entry_dba::FAILED; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); continue; } $mret = $interface->{$method}($args, $this); if ($mret !== true) { $error = "\$interface->{$method}(\$args, \$this) returned '{$mret}', errstr: " . midcom_connection::get_error_string(); $this->print_error($error); debug_add($error, MIDCOM_LOG_ERROR); debug_add('$interface is ' . get_class($interface)); debug_print_r('$args', $args); //PONDER: Delete instead ? (There is currently nothing we do with failed entries) $entry->status = midcom_services_at_entry_dba::FAILED; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); } else { midcom::get('auth')->request_sudo('midcom.services.at'); $entry->delete(); midcom::get('auth')->drop_sudo(); } } }
/** * Create a new style for the topic * * @param string $style_name Name of the style * @return string Style path */ private function _create_style($style_name) { if (isset($GLOBALS['midcom_style_inherited'])) { $up = midcom::get('style')->get_style_id_from_path($GLOBALS['midcom_style_inherited']); debug_add("Style inherited from {$GLOBALS['midcom_style_inherited']}"); } else { $up = midcom_connection::get('style'); debug_add("No inherited style found, placing the new style under host style ID: " . midcom_connection::get('style')); } $style = new midcom_db_style(); $style->name = $style_name; $style->up = $up; if (!$style->create()) { debug_print_r('Failed to create a new style due to ' . midcom_connection::get_error_string(), $style, MIDCOM_LOG_WARN); midcom::get('uimessages')->add('edit folder', sprintf(midcom::get('i18n')->get_string('failed to create a new style template: %s', 'midcom.admin.folder'), midcom_connection::get_error_string()), 'error'); return ''; } debug_print_r('New style created', $style); return midcom::get('style')->get_style_path_from_id($style->id); }
function get_style() { if (is_null($this->object)) { $this->object = new midcom_db_style(midcom_connection::get('style')); } return $this->object; }
private function _complete_defaults() { if (midcom_connection::get('config', 'auth_cookie_id')) { $auth_cookie_id = midcom_connection::get('config', 'auth_cookie_id'); } else { // Generate host identifier from Midgard host $auth_cookie_id = "host" . midcom_connection::get('host'); } $this->_default_config['auth_backend_simple_cookie_id'] = $auth_cookie_id; if (class_exists('Memcache')) { $this->_default_config['cache_module_content_backend'] = array('driver' => 'memcached'); $this->_default_config['cache_module_memcache_backend'] = 'memcached'; } if (isset($_SERVER['SERVER_ADDR'])) { $this->_default_config['indexer_reindex_allowed_ips'][] = $_SERVER['SERVER_ADDR']; } $this->_default_config['midcom_site_title'] = $_SERVER['SERVER_NAME']; $this->_default_config['toolbars_simple_css_path'] = MIDCOM_STATIC_URL . "/midcom.services.toolbars/simple.css"; $basedir = "/var/lib/midgard"; // TODO: Would be good to include DB name into the path if (extension_loaded('midgard2')) { $basedir = dirname(midgard_connection::get_instance()->config->sharedir); } else { $prefix = midcom_connection::get('config', 'prefix'); if ($prefix == '/usr/local') { $basedir = '/var/local/lib/midgard'; } } $this->_default_config['midcom_services_rcs_root'] = $basedir . '/rcs'; }