0013312: install from dump with url
[tine20] / tine20 / Setup / Controller.php
index 96a85eb..bbb4ba9 100644 (file)
@@ -1448,8 +1448,36 @@ class Setup_Controller
             throw new Setup_Exception('Tinebase already installed!');
         }
 
-        $mysqlBackupFile = $options['backupDir'] . '/tine20_mysql.sql.bz2';
-        if (! file_exists($mysqlBackupFile)) {
+        $mysqlBackupFile = null;
+        if (isset($options['backupDir'])) {
+            $mysqlBackupFile = $options['backupDir'] . '/tine20_mysql.sql.bz2';
+        } else if (isset($options['backupUrl'])) {
+            // download files first and put them in temp dir
+            $tempDir = Tinebase_Core::getTempDir();
+            foreach (array(
+                         array('file' => 'tine20_config.tar.bz2', 'param' => 'config'),
+                         array('file' => 'tine20_mysql.sql.bz2', 'param' => 'db'),
+                         array('file' => 'tine20_files.tar.bz2', 'param' => 'files')
+                    ) as $download) {
+                if (isset($options[$download['param']])) {
+                    $fileUrl = $options['backupUrl'] . '/' . $download['file'];
+                        Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Downloading ' . $fileUrl);
+                    $targetFile = $tempDir . DIRECTORY_SEPARATOR . $download['file'];
+                    if ($download['param'] === 'db') {
+                        $mysqlBackupFile = $targetFile;
+                    }
+                    file_put_contents(
+                        $targetFile,
+                        fopen($fileUrl, 'r')
+                    );
+                }
+            }
+            $options['backupDir'] = $tempDir;
+        } else {
+            throw new Setup_Exception("backupDir or backupUrl param required");
+        }
+
+        if (! $mysqlBackupFile || ! file_exists($mysqlBackupFile)) {
             throw new Setup_Exception("$mysqlBackupFile not found");
         }