Index: panels_mini/panels_mini.module =================================================================== RCS file: /cvs/drupal/contributions/modules/panels/panels_mini/Attic/panels_mini.module,v retrieving revision 1.1.2.25 diff -u -r1.1.2.25 panels_mini.module --- panels_mini/panels_mini.module 24 May 2008 04:59:05 -0000 1.1.2.25 +++ panels_mini/panels_mini.module 26 May 2008 21:59:01 -0000 @@ -923,6 +923,19 @@ // Database functions. /** + * A list of the fields used in the panel_mini table. + */ +function panels_mini_fields() { + return array( + "name" => "'%s'", + "title" => "'%s'", + "contexts" => "'%s'", + "requiredcontexts" => "'%s'", + "relationships" => "'%s'", + ); +} + +/** * Sanitize a mini, to guarantee certain data is as we believe it will be. */ function panels_mini_sanitize($mini) { @@ -1018,59 +1031,55 @@ * Save a mini panel. */ function panels_mini_save(&$panel_mini) { - $display = panels_save_display($panel_mini->display); + // Save the display if one was given to us. + if (!empty($panel_mini->display)) { + $display = panels_save_display($panel_mini->display); + } + + // Ensure empty values get translated correctly. + // Also make sure we don't mess up the original. + $mini = drupal_clone(panels_mini_sanitize($panel_mini)); + + // Now we can proceed to saving the mini panel itself. + $fields = $types = $values = $pairs = array(); + + // If pid is set to our "magic value", this is an insert, otherwise an update. + $insert = $mini->pid && $mini->pid == 'new'; + + // Build arrays of fields and types (resp. pairs of both) and of values. + foreach (panels_mini_fields() as $field => $type) { + // Skip empty values. + if (isset($mini->$field)) { + if ($insert) { + $fields[] = $field; + $types[] = $type; + } + else { + $pairs[] = "$field = $type"; + } - if ($panel_mini->pid && $panel_mini->pid != 'new') { - db_query( - "UPDATE {panels_mini} SET " . - "did = %d, " . - "name = '%s', " . - "title = '%s', " . - "relationships = '%s', " . - "contexts = '%s', " . - "requiredcontexts = '%s' " . - "WHERE pid = %d", - $panel_mini->did, - $panel_mini->name, - $panel_mini->title, - serialize($panel_mini->relationships), - serialize($panel_mini->contexts), - serialize($panel_mini->requiredcontexts), - $panel_mini->pid - ); + // Build the $values array, serializing some fields. + $serialize = in_array($field, array('contexts', 'requiredcontexts', 'relationships')); + $values[] = $serialize ? serialize($mini->$field) : $mini->$field; + } + } + + if ($insert) { + // Determine the new primary key. + $mini->pid = db_next_id('{panels_mini}_pid'); + // Build the query adding the new primary key and the did. + $sql = 'INSERT INTO {panels_mini} (' . implode(', ', $fields) . ', pid, did) VALUES (' . implode(', ', $types) . ', %d, %d)'; + $values[] = $mini->pid; + $values[] = $display->did; } else { - $panel_mini->pid = db_next_id("{panels_mini}_pid"); - db_query( - "INSERT INTO {panels_mini} ( " . - "pid, " . - "name, " . - "did, " . - "title, " . - "relationships, " . - "contexts, " . - "requiredcontexts " . - ") " . - "VALUES (" . - "%d, " . - "'%s', " . - "%d, " . - "'%s', " . - "'%s', " . - "'%s', " . - "'%s'" . - ")", - $panel_mini->pid, - $panel_mini->name, - $display->did, - $panel_mini->title, - serialize($panel_mini->relationships), - serialize($panel_mini->contexts), - serialize($panel_mini->requiredcontexts) - ); + // Build the query filtering by the primary key. + $sql = 'UPDATE {panels_mini} SET ' . implode(', ', $pairs) . ' WHERE pid = %d'; + $values[] = $mini->pid; } + db_query($sql, $values); - return $panel_mini->pid; + return $mini->pid; } /** @@ -1088,7 +1097,7 @@ */ function panels_mini_export($panel_mini, $prefix = '') { $output = ''; - $fields = array('name', 'title', 'requiredcontexts', 'contexts', 'relationships'); + $fields = panels_mini_fields(); $output .= $prefix . '$mini = new stdClass()' . ";\n"; $output .= $prefix . '$mini->pid = \'new\'' . ";\n"; foreach ($fields as $field) { Index: panels_page/panels_page.module =================================================================== RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.module,v retrieving revision 1.1.2.47 diff -u -r1.1.2.47 panels_page.module --- panels_page/panels_page.module 24 May 2008 23:26:16 -0000 1.1.2.47 +++ panels_page/panels_page.module 26 May 2008 21:59:02 -0000 @@ -1019,8 +1019,8 @@ if (!empty($panel_page->display)) { $display = panels_save_display($panel_page->display); } - // Ensure empty values get translated correctly. Also make sure we don't - // mess up the original. + // Ensure empty values get translated correctly. + // Also make sure we don't mess up the original. $page = drupal_clone(panels_page_sanitize($panel_page)); // Check to see if we need to save any imported displays. @@ -1031,53 +1031,48 @@ unset($page->displays[$did]['display']); } } - // serialize the access string. - $page->access = $page->access ? implode(', ', $page->access) : ''; - $page->arguments = serialize($page->arguments); - $page->displays = serialize($page->displays); - $page->contexts = serialize($page->contexts); - $page->relationships = serialize($page->relationships); - $page->switcher_options = serialize($page->switcher_options); + // Now we can proceed to saving the panel page itself. + $fields = $types = $values = $pairs = array(); - // Create strings for our query from the list of fields. - $fields = panels_page_fields(); - foreach ($fields as $field => $value) { - if (isset($page->$field)) { - $f[] = $field; - $q[] = $value; - $v[] = $page->$field; - } - } + // If pid is set to our "magic value", this is an insert, otherwise an update. + $insert = $page->pid && $page->pid == 'new'; - if ($page->pid && $page->pid != 'new') { - if (empty($page->name)) { - $page->name = 'panel_page_' . $page->pid; - } - $query = ''; - foreach ($f as $id => $field) { - if ($query) { - $query .= ', '; + // Serialize the access string. + $page->access = $page->access ? implode(', ', $page->access) : ''; + + // Build arrays of fields and types (resp. pairs of both) and of values. + foreach (panels_page_fields() as $field => $type) { + // Skip empty values. + if (isset($page->$field)) { + if ($insert) { + $fields[] = $field; + $types[] = $type; + } + else { + $pairs[] = "$field = $type"; } - $query .= "$f[$id] = " . $q[$id]; - } - $v[] = $page->pid; - db_query("UPDATE {panels_page} SET $query WHERE pid = %d", $v); + // Build the $values array, serializing some fields. + $serialize = in_array($field, array('arguments', 'displays', 'contexts', 'relationships', 'switcher_options')); + $values[] = $serialize ? serialize($page->$field) : $page->$field; + } + } + + if ($insert) { + // Determine the new primary key. + $page->pid = db_next_id('{panels_page}_pid'); + // Build the query adding the new primary key and the did. + $sql = 'INSERT INTO {panels_page} (' . implode(', ', $fields) . ', pid, did) VALUES (' . implode(', ', $types) . ', %d, %d)'; + $values[] = $page->pid; + $values[] = $display->did; } else { - $page->pid = db_next_id("{panels_page}_pid"); - // Tack our pid and did onto the query. These aren't listed as 'fields' because - // they can't be updated; once set they are permanent. - $v[] = $page->pid; - $v[] = $display->did; - - if (empty($page->name)) { - $page->name = 'panel_page_' . $page->pid; - } - // Yes, this is kind of long but it's a lot easier to match up values. - db_query("INSERT INTO {panels_page} ( " . implode(', ', $f) . ", pid, did) VALUES (" . implode(', ', $q) . ", %d, %d)", $v); + // Build the query filtering by the primary key. + $sql = 'UPDATE {panels_page} SET ' . implode(', ', $pairs) . ' WHERE pid = %d'; + $values[] = $page->pid; } + db_query($sql, $values); menu_rebuild(); return $page->pid; Index: panels_views/panels_views.module =================================================================== RCS file: /cvs/drupal/contributions/modules/panels/panels_views/Attic/panels_views.module,v retrieving revision 1.1.2.18 diff -u -r1.1.2.18 panels_views.module --- panels_views/panels_views.module 24 May 2008 04:59:04 -0000 1.1.2.18 +++ panels_views/panels_views.module 26 May 2008 21:59:02 -0000 @@ -1235,57 +1235,44 @@ /** * Write a panel view to the database. */ -function panels_views_save($pv) { - $keys = $values = ""; - $args = array(); - - // If we were truly generic, this whole 'pvid' thing would be pulled - // from field data. But we're not because it's unnecessary extra - // work. - $insert = empty($pv->pvid); +function panels_views_save($panel_view) { + $fields = $types = $values = $pairs = array(); - $names = panels_views_pane_fields(); - // Build SQL for the keys. - foreach ($names as $name => $data) { - // skip the primary key here. - if (!empty($data['primary'])) { - if (!$insert) { - continue; + // If pvid is empty, this is an insert, otherwise an update. + $insert = empty($panel_view->pvid); + + // Build arrays of fields and types (resp. pairs of both) and of values. + foreach (panels_views_pane_fields() as $field => $data) { + $primary = !empty($data['primary']); + // Skip primary key and empty values. + if (!$primary && isset($panel_view->$field)) { + if ($insert) { + $fields[] = $field; + $types[] = $data['arg']; } else { - $pv->pvid = db_next_id('{panels_views}_pvid'); - } - } - - if ($keys) { - $keys .= ', '; - } - if ($insert) { - // $values only used when inserting. - if ($values) { - $values .= ', '; + $pairs[] = "$field = $data[arg]"; } - $keys .= $name; - $values .= $data['arg']; - } - else { - $keys .= "$name = $data[arg]"; - } - if (!empty($data['serialize'])) { - $args[] = serialize($pv->$name); - } - else { - $args[] = $pv->$name; + + // Build the $values array, serializing some fields. + $serialize = !empty($data['serialize']); + $values[] = $serialize ? serialize($panel_view->$field) : $panel_view->$field; } } + if ($insert) { - $sql = "INSERT INTO {panels_views} ($keys) VALUES ($values)"; + // Determine the new primary key. + $panel_view->pvid = db_next_id('{panels_views}_pvid'); + // Build the query adding the new primary key. + $sql = 'INSERT INTO {panels_views} (' . implode(', ', $fields) . ', pvid) VALUES (' . implode(', ', $types) . ', %d)'; + $values[] = $panel_view->pvid; } else { - $sql = "UPDATE {panels_views} SET $keys WHERE pvid = %d"; - $args[] = $pv->pvid; + // Build the query filtering by the primary key. + $sql = "UPDATE {panels_views} SET' . implode(', ', $pairs) . 'WHERE pvid = %d"; + $values[] = $panel_view->pvid; } - db_query($sql, $args); + db_query($sql, $values); } /**