/** * import a sql script into the current profile. * * The name of the script should be store in install/$name.databasetype.sql * in the directory of the component. (replace databasetype by mysql, pgsql etc.) * You can however provide a script compatible with all databases, but then * you should indicate the full name of the script, with a .sql extension. * * @param string $name the name of the script * @param string $module the module from which we should take the sql file. null for the current module * @param boolean $inTransaction indicate if queries should be executed inside a transaction */ protected final function execSQLScript($name, $module = null, $inTransaction = true) { $conn = $this->dbConnection(); $tools = $this->dbTool(); if ($module) { $conf = $this->entryPoint->getConfigObj()->_modulesPathList; if (!isset($conf[$module])) { throw new Exception('execSQLScript : invalid module name'); } $path = $conf[$module]; } else { $path = $this->path; } $file = $path . 'install/' . $name; if (substr($name, -4) != '.sql') { $file .= '.' . $conn->dbms . '.sql'; } if ($inTransaction) { $conn->beginTransaction(); } try { $tools->execSQLScript($file); if ($inTransaction) { $conn->commit(); } } catch (\Exception $e) { if ($inTransaction) { $conn->rollback(); } throw $e; } }