/** * Imports a SQL dump into the database. * This function can not be called statically. * @returns True if successful, false if not successful and report_errors = false or * Error object if report_errors = true */ public static function import($text, $report_errors = true) { PHPWS_DB::touchDB(); // first_import makes sure at least one query was completed // successfully $first_import = false; $sqlArray = PHPWS_Text::sentence($text); $error = false; foreach ($sqlArray as $sqlRow) { if (empty($sqlRow) || preg_match("/^[^\\w\\d\\s\\(\\)]/i", $sqlRow)) { continue; } $sqlCommand[] = $sqlRow; if (preg_match("/;\$/", $sqlRow)) { $query = implode(' ', $sqlCommand); $sqlCommand = array(); if (!DB_ALLOW_TABLE_INDEX && preg_match('/^create index/i', $query)) { continue; } PHPWS_DB::homogenize($query); $result = PHPWS_DB::query($query); if (DB::isError($result)) { if ($report_errors) { return $result; } else { PHPWS_Error::log($result); $error = true; } } $first_import = true; } } if (!$first_import) { if ($report_errors) { return PHPWS_Error::get(PHPWS_DB_IMPORT_FAILED, 'core', 'PHPWS_DB::import'); } else { PHPWS_Error::log(PHPWS_DB_IMPORT_FAILED, 'core', 'PHPWS_DB::import'); $error = true; } } if ($error) { return false; } else { return true; } }