/** * Displays an article edit view. * * Note, that the article for non-index mode operation is automatically determined in the can_handle * phase. * * If create privileges apply, we relocate to the index creation article * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_create($handler_id, array $args, array &$data) { $this->_content_topic->require_do('midgard:create'); $this->_schema = $args[0]; if ($handler_id == 'createindex') { $this->_indexmode = true; } $data['controller'] = $this->get_controller('create'); switch ($data['controller']->process_form()) { case 'save': /** * http://trac.midgard-project.org/ticket/809 should have taken care of this. * BUT: to be extra careful, let's do this sanity-check anyway. */ if (strlen($this->_article->name) == 0) { // Generate something to avoid empty "/" links in case of failures $this->_article->name = time(); $this->_article->update(); } // Index the article $indexer = midcom::get('indexer'); net_nehmer_static_viewer::index($data['controller']->datamanager, $indexer, $this->_content_topic); if ($this->_article->name === 'index') { return new midcom_response_relocate(''); } return new midcom_response_relocate("{$this->_article->name}/"); case 'cancel': return new midcom_response_relocate(''); } $this->_prepare_request_data(); $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description); midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}"); $this->add_breadcrumb("create/{$this->_schema}/", sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description)); }
/** * Displays an article edit view. * * Note, that the article for non-index mode operation is automatically determined in the can_handle * phase. * * If create privileges apply, we relocate to the index creation article * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_create($handler_id, array $args, array &$data) { $this->_content_topic->require_do('midgard:create'); $this->_schema = $args[0]; if ($handler_id == 'createindex') { $this->_indexmode = true; } $data['controller'] = $this->get_controller('create'); switch ($data['controller']->process_form()) { case 'save': // #809 should have taken care of this, but see same place in n.n.static if (strlen($this->_article->name) == 0) { // Generate something to avoid empty "/" links in case of failures $this->_article->name = time(); $this->_article->update(); } // Index the article $indexer = midcom::get('indexer'); net_nehmer_blog_viewer::index($data['controller']->datamanager, $indexer, $this->_content_topic); // *** FALL THROUGH *** // *** FALL THROUGH *** case 'cancel': return new midcom_response_relocate(''); } $this->_prepare_request_data(); $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description); midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}"); $this->add_breadcrumb("create/{$this->_schema}/", sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description)); }
function import_file($file, $parent_id) { $qb = midcom_db_article::new_query_builder(); $qb->add_constraint('topic', '=', $parent_id); $qb->add_constraint('name', '=', $file->name); $existing = $qb->execute(); if (count($existing) > 0 && $existing[0]->topic == $parent_id) { $article = $existing[0]; echo "Using existing article {$article->name} (#{$article->id}) from #{$article->topic}\n"; } else { $article = new midcom_db_article(); $article->topic = $parent_id; $article->name = $file->name; if (!$article->create()) { echo "Failed to create article {$article->name}: " . midcom_connection::get_error_string() . "\n"; return false; } echo "Created article {$article->name} (#{$article->id}) under #{$article->topic}\n"; } $article->title = $file->title; $article->content = $file->content; return $article->update(); }