Author: mj
Date: Sun Oct 16 16:01:39 2011
New Revision: 10120

Log:
Complete search-replace functionality (warning workflow still TODO), remove 
advanced search form defaults.

Modified:
   trunk/apps/qubit/modules/search/actions/advancedAction.class.php
   trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
   trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php

Modified: trunk/apps/qubit/modules/search/actions/advancedAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/advancedAction.class.php    Sun Oct 
16 00:57:27 2011        (r10119)
+++ trunk/apps/qubit/modules/search/actions/advancedAction.class.php    Sun Oct 
16 16:01:39 2011        (r10120)
@@ -37,14 +37,7 @@
       $this->addField($name);
     }
 
-    $defaults = array(
-      'searchFields' => array(0 => array('operator' => 'not', 'query' => 
'abc', 'field' => 'title', 'match' => 'phrase')),
-      'repository' => '',
-      'media' => '',
-      'hasDigitalObject' => ''
-    );
-
-    $this->form->bind($request->getRequestParameters() + 
$request->getGetParameters() + $request->getPostParameters() + $defaults);
+    $this->form->bind($request->getRequestParameters() + 
$request->getGetParameters() + $request->getPostParameters());
 
     if ($this->form->isValid())
     {

Modified: trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php       
Sun Oct 16 00:57:27 2011        (r10119)
+++ trunk/apps/qubit/modules/search/actions/globalReplaceAction.class.php       
Sun Oct 16 16:01:39 2011        (r10120)
@@ -35,8 +35,36 @@
         return;
       }
 
-      // TODO
-      // process replacement action
+      // Process replacement on each IO
+      // NB: could this be made faster by reading a batch of IDs?
+      foreach ($this->pager->hits as $hit)
+      {
+        $io = QubitInformationObject::getById($hit->getDocument()->id);
+
+        if (isset($request->allowRegex))
+        {
+          $pattern = '/' . strtr($request->pattern, array('/' => '\/')) . '/';
+          if (!isset($request->caseSensitive)) $pattern .= 'i';
+
+          $replacement = strtr($request->replacement, array('/' => '\/'));
+
+          $replaced = preg_replace($pattern, $replacement, 
$io->__get($request->column));
+        }
+        elseif (isset($request->caseSensitive))
+        {
+          $replaced = str_replace($request->pattern, $request->replacement, 
$io->__get($request->column));
+        }
+        else
+        {
+          $replaced = str_ireplace($request->pattern, $request->replacement, 
$io->__get($request->column));
+        }
+
+        $io->__set($request->column, $replaced);
+        $io->save();
+      }
+
+      // force refresh of index to keep sync
+      QubitSearch::getInstance()->optimize();
 
       // When complete, redirect to GSR home
       $this->redirect(array('module' => 'search', 'action' => 
'globalReplace'));
@@ -66,5 +94,14 @@
 
     $this->form->setValidator('replacement', new sfValidatorString);
     $this->form->setWidget('replacement', new sfWidgetFormInput);
+
+    // TODO
+    // FIXME
+    $this->form->setDefault('caseSensitive', true);
+    $this->form->setValidator('caseSensitive', new sfValidatorBoolean);
+    $this->form->setWidget('caseSensitive', new 
sfWidgetFormInputCheckbox(array(), array('value' => 1)));
+
+    $this->form->setValidator('allowRegex', new sfValidatorBoolean);
+    $this->form->setWidget('allowRegex', new sfWidgetFormInputCheckbox);
   }
 }

Modified: trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php  Sun Oct 
16 00:57:27 2011        (r10119)
+++ trunk/apps/qubit/modules/search/templates/globalReplaceSuccess.php  Sun Oct 
16 16:01:39 2011        (r10120)
@@ -22,6 +22,16 @@
               <?php echo $form->column->render() ?>
             </td>
           </tr>
+          <tr>
+            <td colspan="2">
+              <?php echo __('Case-sensitive') ?>
+              <?php echo $form->caseSensitive->render() ?>
+            </td>
+            <td colspan="3">
+              <?php echo __('Use regular expression syntax') ?>
+              <?php echo $form->allowRegex->render() ?>
+            </td>
+          </tr>
         </tbody>
       </table>
     </div>

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to