Tinebase - update script to ensure shared folders have acl node
authorPaul Mehrer <p.mehrer@metaways.de>
Fri, 14 Jul 2017 14:08:27 +0000 (16:08 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Fri, 14 Jul 2017 14:41:34 +0000 (16:41 +0200)
for Filemanager and MailFiler

Change-Id: I4afb62ffd73720ae32239ac0e98362fc25a7be86
Reviewed-on: http://gerrit.tine20.com/customers/5177
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tine20/Tinebase/Setup/Update/Release10.php
tine20/Tinebase/Setup/setup.xml

index 86cbe87..ff5787e 100644 (file)
@@ -1793,7 +1793,7 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
      */
     public function update_36()
     {
-        $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'container_acl')->query(Zend_DB::FETCH_ASSOC);
+        $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'container_acl')->query(Zend_Db::FETCH_ASSOC);
         $quotedId = $this->_db->quoteIdentifier('id');
         $quotedContainerId = $this->_db->quoteIdentifier('container_id');
         $quotedAccountType = $this->_db->quoteIdentifier('account_type');
@@ -1810,7 +1810,7 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
             );
         }
 
-        $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'tree_node_acl')->query(Zend_DB::FETCH_ASSOC);
+        $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'tree_node_acl')->query(Zend_Db::FETCH_ASSOC);
         $quotedRecordId = $this->_db->quoteIdentifier('record_id');
         foreach ($result->fetchAll() as $row) {
             $this->_db->update(SQL_TABLE_PREFIX . 'tree_node_acl',
@@ -1828,7 +1828,7 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
         $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'container_acl', array($command->getAggregate('id'),
             new Zend_Db_Expr('count(*) AS c')))
             ->group(array('container_id', 'account_type', 'account_id', 'account_grant'))
-            ->having('c > 1')->query(Zend_DB::FETCH_NUM);
+            ->having('c > 1')->query(Zend_Db::FETCH_NUM);
         foreach ($result->fetchAll() as $row) {
             $ids = explode(',', ltrim(rtrim($row[0], '}'), '{'));
             array_pop($ids);
@@ -1838,7 +1838,7 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
         $result = $this->_db->select()->from(SQL_TABLE_PREFIX . 'tree_node_acl', array($command->getAggregate('id'),
             new Zend_Db_Expr('count(*) AS c')))
             ->group(array('record_id', 'account_type', 'account_id', 'account_grant'))
-            ->having('c > 1')->query(Zend_DB::FETCH_NUM);
+            ->having('c > 1')->query(Zend_Db::FETCH_NUM);
         foreach ($result->fetchAll() as $row) {
             $ids = explode(',', ltrim(rtrim($row[0], '}'), '{'));
             array_pop($ids);
@@ -1916,4 +1916,58 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
         }
         $this->setApplicationVersion('Tinebase', '10.37');
     }
+
+    /**
+     * update to 10.38
+     *
+     * set shared folders acl not if not set
+     */
+    public function update_37()
+    {
+        $fileSystem = Tinebase_FileSystem::getInstance();
+        $inheritPropertyMethod = $this->_getProtectedMethod($fileSystem, '_recursiveInheritPropertyUpdate');
+        if (Tinebase_Application::getInstance()->isInstalled('Filemanager')) {
+            try {
+                $node = $fileSystem->stat('/Filemanager/folders/shared');
+                if (null === $node->acl_node) {
+                    $fileSystem->setGrantsForNode($node, Tinebase_Model_Grants::getDefaultGrants(array(
+                        Tinebase_Model_Grants::GRANT_DOWNLOAD => true
+                    ), array(
+                        Tinebase_Model_Grants::GRANT_PUBLISH => true
+                    )));
+                    $inheritPropertyMethod->invoke($fileSystem, $node, 'acl_node', $node->acl_node, null);
+                }
+            } catch(Tinebase_Exception_NotFound $tenf) {}
+        }
+        if (Tinebase_Application::getInstance()->isInstalled('MailFiler')) {
+            try {
+                $node = $fileSystem->stat('/MailFiler/folders/shared');
+                if (null === $node->acl_node) {
+                    $fileSystem->setGrantsForNode($node, Tinebase_Model_Grants::getDefaultGrants(array(
+                        Tinebase_Model_Grants::GRANT_DOWNLOAD => true
+                    ), array(
+                        Tinebase_Model_Grants::GRANT_PUBLISH => true
+                    )));
+                    $inheritPropertyMethod->invoke($fileSystem, $node, 'acl_node', $node->acl_node, null);
+                }
+            } catch(Tinebase_Exception_NotFound $tenf) {}
+        }
+
+        $this->setApplicationVersion('Tinebase', '10.38');
+    }
+
+    /**
+     * GetProtectedMethod constructor.
+     * @param $object
+     * @param $method
+     * @return ReflectionMethod
+     */
+    protected function _getProtectedMethod($object, $method)
+    {
+        $class = new ReflectionClass($object);
+        $method = $class->getMethod($method);
+        $method->setAccessible(true);
+
+        return $method;
+    }
 }
index c22d2e2..f1057af 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Tinebase</name>
-    <version>10.37</version>
+    <version>10.38</version>
     <tables>
         <table>
             <name>applications</name>