diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2016-01-15 04:35:39 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-01-15 05:00:46 +0300 |
commit | d5ddc0a91ce7fa6b8836ffa6d5573f767e3cea2e (patch) | |
tree | 8e6f9887a41779173f71fd443938cb98b0bbc593 /core | |
parent | 6d00a6a60f3d0332fa0b3d6ae5562c9339a6e962 (diff) |
try to use path from secure_file_priv variable
Diffstat (limited to 'core')
-rw-r--r-- | core/Db/BatchInsert.php | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php index 254e03d2d4..cf3918580c 100644 --- a/core/Db/BatchInsert.php +++ b/core/Db/BatchInsert.php @@ -56,12 +56,14 @@ class BatchInsert */ public static function tableInsertBatch($tableName, $fields, $values, $throwException = false) { - $filePath = StaticContainer::get('path.tmp') . '/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv'; - $loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile']; if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) { + + $path = self::getBestPathForLoadData(); + $filePath = $path . $tableName . '-' . Common::generateUniqId() . '.csv'; + try { $fileSpec = array( 'delim' => "\t", @@ -94,17 +96,36 @@ class BatchInsert throw $e; } } - } - // if all else fails, fallback to a series of INSERTs - if(file_exists($filePath)){ - @unlink($filePath); + // if all else fails, fallback to a series of INSERTs + if (file_exists($filePath)) { + @unlink($filePath); + } } - + self::tableInsertBatchIterate($tableName, $fields, $values); + return false; } + private static function getBestPathForLoadData() + { + try { + $path = Db::fetchOne('SELECT @@secure_file_priv'); // was introduced in 5.0.38 + } catch (Exception $e) { + // we do not rethrow exception as an error is expected if MySQL is < 5.0.38 + // in this case tableInsertBatch might still work + } + + if (empty($path) || !is_dir($path) || !is_writable($path)) { + $path = StaticContainer::get('path.tmp') . '/assets/'; + } elseif (!Common::stringEndsWith($path, '/')) { + $path .= '/'; + } + + return $path; + } + /** * Batch insert into table from CSV (or other delimited) file. * |