Commit 65d6740e authored by damiankloip's avatar damiankloip Committed by tim.plunkett
Browse files

Removed some un-needed crud operations from view object

parent 7cb7d2e7
......@@ -1774,186 +1774,6 @@ function end_query_capture() {
$this->additional_queries = $temp;
}
/**
* Static factory method to load a list of views based upon a $where clause.
*
* Although this method could be implemented to simply iterate over views::load(),
* that would be very slow. Buiding the views externally from unified queries is
* much faster.
*/
static function load_views() {
$result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
$views = array();
// Load all the views.
foreach ($result as $data) {
$view = new View();
$view->load_row($data);
$view->loaded = TRUE;
$view->type = t('Normal');
$views[$view->name] = $view;
$names[$view->vid] = $view->name;
}
// Stop if we didn't get any views.
if (!$views) {
return array();
}
// Now load all the subtables:
foreach (View::db_objects() as $key => $object) {
$table_name = "views_" . $key;
$object_name = "Views$object";
$result = db_query("SELECT * FROM {{$table_name}} WHERE vid IN (:vids) ORDER BY vid, position",
array(':vids' => array_keys($names)));
foreach ($result as $data) {
$object = new $object_name(FALSE);
$object->load_row($data);
// Because it can get complicated with this much indirection,
// make a shortcut reference.
$location = &$views[$names[$object->vid]]->$key;
// If we have a basic id field, load the item onto the view based on
// this ID, otherwise push it on.
if (!empty($object->id)) {
$location[$object->id] = $object;
}
else {
$location[] = $object;
}
}
}
return $views;
}
/**
* Save the view to the database. If the view does not already exist,
* A vid will be assigned to the view and also returned from this function.
*/
function save() {
if ($this->vid == 'new') {
$this->vid = NULL;
}
// If there is no vid, check if a view with this machine name already exists.
elseif (empty($this->vid)) {
$vid = db_query("SELECT vid from {views_view} WHERE name = :name", array(':name' => $this->name))->fetchField();
$this->vid = $vid ? $vid : NULL;
}
$transaction = db_transaction();
try {
// If we have no vid or our vid is a string, this is a new view.
if (!empty($this->vid)) {
// remove existing table entries
foreach ($this->db_objects() as $key => $object) {
db_delete('views_' . $key)
->condition('vid', $this->vid)
->execute();
}
}
$this->save_row(!empty($this->vid) ? 'vid' : FALSE);
// Save all of our subtables.
foreach ($this->db_objects() as $key => $object) {
$this->_save_rows($key);
}
}
catch (Exception $e) {
$transaction->rollback();
watchdog_exception('views', $e);
throw $e;
}
$this->save_locale_strings();
// Clear caches.
views_invalidate_cache();
// @todo Remove this.
// Explicitly rebuild the menu.
menu_router_rebuild();
}
/**
* Save a row to the database for the given key, which is one of the
* keys from View::db_objects()
*/
function _save_rows($key) {
$count = 0;
foreach ($this->$key as $position => $object) {
$object->position = ++$count;
$object->vid = $this->vid;
$object->save_row();
}
}
/**
* Delete the view from the database.
*/
function delete($clear = TRUE) {
if (empty($this->vid)) {
return;
}
db_delete('views_view')
->condition('vid', $this->vid)
->execute();
// Delete from all of our subtables as well.
foreach ($this->db_objects() as $key => $object) {
db_delete('views_'. $key)
->condition('vid', $this->vid)
->execute();
}
cache('cache_views')->delete('views_query:' . $this->name);
if ($clear) {
// Clear caches.
views_invalidate_cache();
}
}
/**
* Export a view as PHP code.
*/
function export($indent = '') {
$this->init_display();
$this->init_query();
$output = '';
$output .= $this->export_row('view', $indent);
// Set the API version
$output .= $indent . '$view->api_version = \'' . views_api_version() . "';\n";
$output .= $indent . '$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */' . "\n";
foreach ($this->display as $id => $display) {
$output .= "\n" . $indent . "/* Display: $display->display_title */\n";
$output .= $indent . '$handler = $view->new_display(' . ctools_var_export($display->display_plugin, $indent) . ', ' . ctools_var_export($display->display_title, $indent) . ', \'' . $id . "');\n";
if (empty($display->handler)) {
// @todo -- probably need a method of exporting broken displays as
// they may simply be broken because a module is not installed. That
// does not invalidate the display.
continue;
}
$output .= $display->handler->export_options($indent, '$handler->options');
}
// Give the localization system a chance to export translatables to code.
if ($this->init_localization()) {
$this->export_locale_strings('export');
$translatables = $this->localization_plugin->export_render($indent);
if (!empty($translatables)) {
$output .= $translatables;
}
}
return $output;
}
/**
* Make a copy of this view that has been sanitized of all database IDs
* and handlers and other stuff.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment