function safecracker_submit_entry_end($obj) { $this->site_pages = $this->sql->get_site_pages(TRUE); $this->EE->load->helper('url'); // The constants in this safecracker game. $channel_id = $obj->channel['channel_id']; $channel_type = $this->sql->get_channel_type($channel_id); if ($channel_type == NULL) { return; } // If we're not working with Structure data, let's kill this quickly. if (!isset($obj->entry['entry_id']) || $channel_type != 'page' && $channel_type != 'listing') { return; } // These may not always be available so putting them *after* the conditional $entry_id = $obj->entry['entry_id']; // This defaults to false if not a listing entry $listing_entry = $this->sql->get_listing_entry($entry_id); /* |------------------------------------------------------------------------- | Template ID |------------------------------------------------------------------------- */ $default_template = $listing_entry ? $listing_entry['template_id'] : $this->sql->get_default_template($channel_id); $template_id = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_template_id'), structure_array_get($this->site_pages['templates'], $entry_id)); if (!$this->sql->is_valid_template($template_id)) { $template_id = $default_template; } /* |------------------------------------------------------------------------- | URI |------------------------------------------------------------------------- */ $default_uri = $listing_entry ? structure_array_get($listing_entry, 'uri') : structure_array_get($this->site_pages['uris'], $entry_id); $uri = Structure_Helper::tidy_url(pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_uri'), Structure_Helper::get_slug($default_uri), $obj->entry['url_title'])); /* |------------------------------------------------------------------------- | Parent ID |------------------------------------------------------------------------- */ $default_parent_id = $channel_type == 'listing' ? $this->sql->get_listing_parent($channel_id) : 0; $parent_id = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_parent_id'), $this->sql->get_parent_id($entry_id, null), $default_parent_id); /* |------------------------------------------------------------------------- | Parent URI |------------------------------------------------------------------------- */ $parent_uri = structure_array_get($this->site_pages['uris'], $parent_id, '/'); /* |------------------------------------------------------------------------- | URL |------------------------------------------------------------------------- */ $url = $channel_type == 'listing' ? $uri : $this->sql->create_full_uri($parent_uri, $uri); /* |------------------------------------------------------------------------- | Listing Channel ID |------------------------------------------------------------------------- */ $listing_cid = $this->sql->get_listing_channel($parent_id); /* |------------------------------------------------------------------------- | Hidden State |------------------------------------------------------------------------- */ $hidden = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_hidden'), $this->sql->get_hidden_state($entry_id), 'n'); /* |------------------------------------------------------------------------- | Entry data to be processed and saved |------------------------------------------------------------------------- */ $entry_data = array('channel_id' => $channel_id, 'entry_id' => $entry_id, 'uri' => $url, 'parent_uri' => $parent_uri, 'template_id' => $template_id, 'parent_id' => $parent_id, 'listing_cid' => $listing_cid, 'hidden' => $hidden); if ($channel_type == 'listing') { $this->sql->set_listing_data($entry_data); } else { require_once PATH_THIRD . 'structure/mod.structure.php'; $this->structure = new Structure(); $this->structure->set_data($entry_data); } }
function upgrade_to_ee2() { /* |-------------------------------------------------------------------------- | Adios, sayonara, and farewell to "Weblogs"! |-------------------------------------------------------------------------- | | We need to remap any references to weblogs or "wid"s to their proper | channel equivelants. | */ if (!$this->EE->db->field_exists('channel_id', 'structure') && !$this->EE->db->field_exists('listing_cid', 'structure')) { $this->EE->dbforge->modify_column('structure', array('weblog_id' => array('name' => 'channel_id', 'type' => 'INT', 'constraint' => 6), 'listing_wid' => array('name' => 'listing_cid', 'type' => 'INT', 'constraint' => 6))); } /* |-------------------------------------------------------------------------- | Table: Structure Channels |-------------------------------------------------------------------------- | | EE1's table structure was heinous. We need to juggle data around for | a bit and reformat it before sticking it in the database. | */ // Grab the EE1 settings and empty them out. $ee1_settings = $this->EE->db->get('structure_settings')->result_array(); $this->EE->db->empty_table('structure_settings'); // Prep the new table $this->create_table_structure_channels(); $structure_channels = array(); // Convert the old data format foreach ($ee1_settings as $setting) { if ($setting['var'] == "action_ajax_move" || $setting['var'] == "module_id" || $setting['var'] == "picker" || $setting['var'] == "url") { continue; } if (strpos($setting['var'], 'type_weblog_') !== FALSE) { $channel_id = str_replace('type_weblog_', '', $setting['var']); $structure_channels[$channel_id]['channel_id'] = $channel_id; $structure_channels[$channel_id]['type'] = $this->resolve_channel_type($setting['var_value']); } elseif (strpos($setting['var'], 'template_weblog_') !== FALSE) { $channel_id = str_replace('template_weblog_', '', $setting['var']); $structure_channels[$channel_id]['channel_id'] = $channel_id; $structure_channels[$channel_id]['template_id'] = $setting['var_value']; } else { // How...? } $structure_channels[$channel_id]['site_id'] = $setting['site_id']; $structure_channels[$channel_id]['channel_id'] = $channel_id; $structure_channels[$channel_id]['split_assets'] = 'n'; $structure_channels[$channel_id]['show_in_page_selector'] = 'y'; // @todo listing channel check } // Populate the Structure Channels table foreach ($structure_channels as $data) { $this->EE->db->insert('structure_channels', $data); } /* |-------------------------------------------------------------------------- | Table: Structure Listings |-------------------------------------------------------------------------- | | Structure for EE1 just jammed everything into two tables without respect | or a care in the world . Let's try to be better citizens, shall we? | */ $this->create_table_structure_listings(); //get all structure entries that have listings $structure_entries = $this->EE->db->from('structure as s')->join('structure_channels as sc', 'sc.channel_id = s.listing_cid')->where('listing_cid !=', 0)->get()->result_array(); $site_pages = $this->EE->config->item('site_pages'); foreach ($structure_entries as $listing_entry) { $data = array('site_id' => $listing_entry['site_id'], 'parent_id' => $listing_entry['channel_id'], 'channel_id' => $listing_entry['listing_cid'], 'template_id' => $listing_entry['template_id']); //find all the entries for this listing $channel_entries = $this->EE->db->from('channel_titles')->where('channel_id', $listing_entry['listing_cid'])->get()->result_array(); foreach ($channel_entries as $channel_entry) { //if this entry is in site_pages get it uri and add it to the structure listings table if (isset($site_pages[$channel_entry['site_id']]['uris'][$channel_entry['entry_id']])) { $listing_entry = array_merge($data, array('entry_id' => $channel_entry['entry_id'], 'uri' => Structure_Helper::get_slug($site_pages[$channel_entry['site_id']]['uris'][$channel_entry['entry_id']]))); $this->EE->db->insert('structure_listings', $listing_entry); } } } /* |-------------------------------------------------------------------------- | Extension |-------------------------------------------------------------------------- | | We don't store any data in the extension, so it's much simpler to just | blow it out and reinstall it ourselves. | */ $this->EE->db->delete('extensions', array('class' => 'Structure_ext')); require_once PATH_THIRD . 'structure/ext.structure.php'; $ext = new Structure_ext(); $ext->activate_extension(); /* |-------------------------------------------------------------------------- | Publish Tab |-------------------------------------------------------------------------- | | We need to tell ExpressionEngine that we have a pile of useful fields to | add into the Publish Tab. | */ $this->EE->load->library('layout'); $this->EE->layout->add_layout_tabs($this->tabs(), 'structure'); $this->EE->db->where('module_name', "Structure"); $this->EE->db->update('modules', array('has_publish_fields' => 'y')); }