Bläddra i källkod

- qbf_load() renamed to qbf_query_load() to avoid a hook_load() feeling
- resaving a loaded query now overwrites the previous version instead of creating a duplicate (bug 351)
- loading a query now also loads its name (bug 352)
- added a phpdoc about qbf_admin_settings()
- removed obsolete commented-out code in _qbf_query_delete()

Frederic G. Marand 16 år sedan
förälder
incheckning
6951ef318a
1 ändrade filer med 20 tillägg och 9 borttagningar
  1. 20 9
      qbf.module

+ 20 - 9
qbf.module

@@ -12,7 +12,7 @@
  * @package QBF
  */
 
-// $Id: qbf.module,v 1.9.2.5 2008-10-05 18:27:13 marand Exp $
+// $Id: qbf.module,v 1.9.2.6 2008-10-07 09:43:06 marand Exp $
 
 /**
  * Saved error reporting level.
@@ -434,10 +434,10 @@ function qbf_query_mapper($arQueryMap = array(), $arDefaults = array()) {
 /**
  * Load a form_values array into a form used by QBF.
  *
- * This is typically useful when loading saved queries using qbf_load().
+ * This is typically useful when loading saved queries using qbf_query_load().
  * For other cases, the mechanisms built within FAPI should be used instead.
  *
- * @see qbf_load()
+ * @see qbf_query_load()
  *
  * @ingroup forms
  * @param array $form
@@ -459,12 +459,15 @@ function qbf_import_values($element, $form_values) {
 /**
  * Load a saved QBF query.
  *
+ * It is not named qbf_load() although this would seem more natural, because a
+ * hook_load() exists and this is not an implementation of this hook.
+ *
  * @see qbf_import_values()
  *
  * @param int $qid
  * @return array A form_values array usable by qbf_import_values
  */
-function qbf_load($qid) {
+function qbf_query_load($qid) {
   $sq = 'SELECT qq.qid, qq.uid, qq.query, qq.name '
       . 'FROM {%s} qq '
       . 'WHERE qq.qid = %d ';
@@ -570,6 +573,13 @@ function _qbf_save($form_id, $form_values) {
     	$arValues[$key] = $value;
       }
 
+    // Avoid duplicates
+    if (!empty($name))
+      {
+      $sq = "DELETE FROM {%s} WHERE name = '%s'";
+      db_query($sq, QBF_TABLE_NAME, $name);
+      }
+
     $sq = 'INSERT INTO {%s} (qid, uid, name, query) '
          ."VALUES           (%d,  %d,  '%s', '%s' ) ";
     $ret = db_next_id('qbf_qid');
@@ -632,14 +642,10 @@ function _qbf_query_delete($qid) {
 
   global $user;
 
-  $query = qbf_load($qid);
+  $query = qbf_query_load($qid);
   $notify = variable_get(QBF_VAR_NOTIFY_DELETE, QBF_DEF_NOTIFY_DELETE);
   $link = l($qid, QBF_PATH_MAIN . '/' . $qid . '/delete');
 
-  // @todo Check safety, this seem dangerous
-  //$usArgs = func_get_args();
-  //$path = implode('/', array_slice($usArgs, 1));
-
   // only valid if valid query, and owner or admin
   if (isset($query->uid) && (($query->uid == $user->uid) || user_access(QBF_PERM_ADMIN)))
     {
@@ -675,6 +681,11 @@ function _qbf_query_delete($qid) {
   drupal_goto();
 }
 
+/**
+ * Implement the former hook_settings().
+ *
+ * @return array
+ */
 function qbf_admin_settings() {
 
   $form = array();