Filemanager - added isIndexed field / filter
authorPaul Mehrer <p.mehrer@metaways.de>
Fri, 2 Jun 2017 12:50:18 +0000 (14:50 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Fri, 2 Jun 2017 13:32:44 +0000 (15:32 +0200)
!usermanual

Change-Id: I5ebb7d1771c9954e859d09092a5d099674586717
Reviewed-on: http://gerrit.tine20.com/customers/4817
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Filemanager/Frontend/JsonTests.php
tests/tine20/Tinebase/FileSystemTest.php
tine20/Tinebase/Model/Tree/Node.php
tine20/Tinebase/Model/Tree/Node/Filter.php
tine20/Tinebase/Model/Tree/Node/IsIndexedFilter.php [new file with mode: 0644]
tine20/Tinebase/Tree/Node.php

index 3021bd6..075ccf3 100644 (file)
@@ -1375,6 +1375,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             array('field' => 'recursive', 'operator' => 'equals',   'value' => 1),
             array('field' => 'path',      'operator' => 'equals',   'value' => '/'),
             array('field' => 'query',     'operator' => 'contains', 'value' => 'color'),
+            array('field' => 'isIndexed', 'operator' => 'equals',   'value' => 0),
         'AND');
         
         $result = $this->_getUit()->searchNodes($filter, array('sort' => 'name', 'start' => 0, 'limit' => 0));
index 3a44ec1..f61387f 100644 (file)
@@ -318,6 +318,7 @@ class Tinebase_FileSystemTest extends TestCase
         $filter = new Tinebase_Model_Tree_Node_Filter(array(
             array('field' => 'id',          'operator' => 'equals',     'value' => $node->getId()),
             array('field' => 'content',     'operator' => 'contains',   'value' => 'phpunit'),
+            array('field' => 'isIndexed',   'operator' => 'equals',     'value' => 1),
         ), /* $_condition = */ '', /* $_options */ array('ignoreAcl' => true));
         $result = $this->_controller->search($filter);
         $this->assertEquals(1, $result->count(), 'didn\'t find file');
@@ -326,6 +327,7 @@ class Tinebase_FileSystemTest extends TestCase
         $filter = new Tinebase_Model_Tree_Node_Filter(array(
             array('field' => 'id',          'operator' => 'equals',     'value' => $node->getId()),
             array('field' => 'content',     'operator' => 'contains',   'value' => 'shooo'),
+            array('field' => 'isIndexed',   'operator' => 'equals',     'value' => 1),
         ), /* $_condition = */ '', /* $_options */ array('ignoreAcl' => true));
         $result = $this->_controller->search($filter);
         $this->assertEquals(0, $result->count(), 'did find file where non should be found');
@@ -349,6 +351,7 @@ class Tinebase_FileSystemTest extends TestCase
         $filter = new Tinebase_Model_Tree_Node_Filter(array(
             array('field' => 'id',          'operator' => 'equals',     'value' => $node->getId()),
             array('field' => 'content',     'operator' => 'contains',   'value' => 'abcde'),
+            array('field' => 'isIndexed',   'operator' => 'equals',     'value' => 1),
         ), /* $_condition = */ '', /* $_options */ array('ignoreAcl' => true));
         $result = $this->_controller->search($filter);
         $this->assertEquals(1, $result->count(), 'didn\'t find file');
@@ -357,6 +360,7 @@ class Tinebase_FileSystemTest extends TestCase
         $filter = new Tinebase_Model_Tree_Node_Filter(array(
             array('field' => 'id',          'operator' => 'equals',     'value' => $node->getId()),
             array('field' => 'content',     'operator' => 'contains',   'value' => 'phpunit'),
+            array('field' => 'isIndexed',   'operator' => 'equals',     'value' => 1),
         ), /* $_condition = */ '', /* $_options */ array('ignoreAcl' => true));
         $result = $this->_controller->search($filter);
         $this->assertEquals(0, $result->count(), 'did find file where non should be found');
index 670abf2..f1e8fbc 100644 (file)
@@ -135,6 +135,7 @@ class Tinebase_Model_Tree_Node extends Tinebase_Record_Abstract
         'available_revisions'   => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'hash'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'indexed_hash'          => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'isIndexed'             => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'size'                  => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'revision_size'         => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'preview_count'         => array(Zend_Filter_Input::ALLOW_EMPTY => true, 'Digits',
index 7c9e7dd..ff05d19 100644 (file)
@@ -48,68 +48,71 @@ class Tinebase_Model_Tree_Node_Filter extends Tinebase_Model_Filter_GrantsFilter
      * @var array filter model fieldName => definition
      */
     protected $_filterModel = array(
-        'query'                => array(
+        'query'                 => array(
             'filter' => 'Tinebase_Model_Filter_Query', 
             'options' => array('fields' => array('name', 'content', 'description'))
         ),
-        'id'                   => array('filter' => 'Tinebase_Model_Filter_Id'),
-        'path'                 => array('filter' => 'Tinebase_Model_Tree_Node_PathFilter'),
-        'parent_id'            => array('filter' => 'Tinebase_Model_Filter_Text'),
-        'name'                 => array('filter' => 'Tinebase_Model_Filter_Text'),
-        'object_id'            => array('filter' => 'Tinebase_Model_Filter_Text'),
+        'id'                    => array('filter' => 'Tinebase_Model_Filter_Id'),
+        'path'                  => array('filter' => 'Tinebase_Model_Tree_Node_PathFilter'),
+        'parent_id'             => array('filter' => 'Tinebase_Model_Filter_Text'),
+        'name'                  => array('filter' => 'Tinebase_Model_Filter_Text'),
+        'object_id'             => array('filter' => 'Tinebase_Model_Filter_Text'),
     // tree_fileobjects table
-        'last_modified_time'   => array(
+        'last_modified_time'    => array(
             'filter' => 'Tinebase_Model_Filter_Date',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'deleted_time'         => array(
+        'deleted_time'          => array(
             'filter' => 'Tinebase_Model_Filter_DateTime',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'creation_time'        => array(
+        'creation_time'         => array(
             'filter' => 'Tinebase_Model_Filter_Date',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'last_modified_by'     => array(
+        'last_modified_by'      => array(
             'filter' => 'Tinebase_Model_Filter_User',
             'options' => array('tablename' => 'tree_fileobjects'
         )),
-        'created_by'           => array(
+        'created_by'            => array(
             'filter' => 'Tinebase_Model_Filter_User',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'type'                 => array(
+        'type'                  => array(
             'filter' => 'Tinebase_Model_Filter_Text', 
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'contenttype'          => array(
+        'contenttype'           => array(
             'filter' => 'Tinebase_Model_Filter_Text',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
-        'description'          => array(
+        'description'           => array(
             'filter' => 'Tinebase_Model_Filter_FullText',
             'options' => array('tablename' => 'tree_fileobjects')
         ),
     // tree_filerevisions table
-        'size'                 => array(
+        'size'                  => array(
             'filter' => 'Tinebase_Model_Filter_Int',
             'options' => array('tablename' => 'tree_filerevisions')
         ),
     // recursive search
-        'recursive'            => array(
+        'recursive'             => array(
             'filter' => 'Tinebase_Model_Filter_Bool'
         ),
-        'tag'                  => array('filter' => 'Tinebase_Model_Filter_Tag', 'options' => array(
+        'tag'                   => array('filter' => 'Tinebase_Model_Filter_Tag', 'options' => array(
             'idProperty' => 'tree_nodes.id',
             'applicationName' => 'Tinebase',
         )),
     // fulltext search
-        'content'              => array(
-            'filter'            => 'Tinebase_Model_Filter_ExternalFullText',
-            'options'           => array(
-                'idProperty' => 'object_id',
+        'content'               => array(
+            'filter'                => 'Tinebase_Model_Filter_ExternalFullText',
+            'options'               => array(
+                'idProperty'            => 'object_id',
             )
         ),
+        'isIndexed'             => array(
+            'filter'                => 'Tinebase_Model_Tree_Node_IsIndexedFilter',
+        )
     );
 
     /**
diff --git a/tine20/Tinebase/Model/Tree/Node/IsIndexedFilter.php b/tine20/Tinebase/Model/Tree/Node/IsIndexedFilter.php
new file mode 100644 (file)
index 0000000..512c687
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Filter
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Paul Mehrer <p.mehrer@metaways.de>
+ */
+
+/**
+ * Tinebase_Model_Tree_Node_IsIndexedFilter
+ *
+ * filters for tree nodes that are indexed or not
+ *
+ * @package     Tinebase
+ * @subpackage  Filter
+ */
+class Tinebase_Model_Tree_Node_IsIndexedFilter extends Tinebase_Model_Filter_Bool
+{
+    /**
+     * appends sql to given select statement
+     *
+     * @param Zend_Db_Select                $_select
+     * @param Tinebase_Backend_Sql_Abstract $_backend
+     */
+    public function appendFilterSql($_select, $_backend)
+    {
+        $db = $_backend->getAdapter();
+
+        // prepare value
+        $op = $this->_value ? ' = ' : ' <> ';
+
+        $quotedField1 = $db->quoteIdentifier('tree_fileobjects.indexed_hash');
+        $quotedField2 = $db->quoteIdentifier('tree_filerevisions.hash');
+        $_select->where($quotedField1 . $op . $quotedField2);
+    }
+}
\ No newline at end of file
index 3eaab2c..21150f6 100644 (file)
@@ -117,7 +117,8 @@ class Tinebase_Tree_Node extends Tinebase_Backend_Sql_Abstract
             /* table  */ array('tree_filerevisions2' => $this->_tablePrefix . 'tree_filerevisions'),
                 /* on     */ $this->_db->quoteIdentifier('tree_fileobjects.id') . ' = ' . $this->_db->quoteIdentifier('tree_filerevisions2.id'),
                 /* select */ array('available_revisions' => Tinebase_Backend_Sql_Command::factory($select->getAdapter())->getAggregate('tree_filerevisions2.revision'))
-            )->group($this->_tableName . '.object_id');
+            )->group($this->_tableName . '.object_id'
+            )->columns('(tree_fileobjects.indexed_hash = tree_filerevisions.hash) AS isIndexed');
             
         return $select;
     }