Skip to content

Commit

Permalink
Extracting DB credentials from env.php (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: [email protected] <DataScience19>
Co-authored-by: Franciszek Wawrzak <[email protected]>
  • Loading branch information
bertod and fsw authored Apr 3, 2020
1 parent 929d898 commit 9681a4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
28 changes: 23 additions & 5 deletions magmi/inc/magmi_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class Magmi_Engine extends DbHelper
*/
public function getEngineInfo()
{
return array("name"=>"Generic Magmi Engine","version"=>"1.1","author"=>"dweeves");
return array("name" => "Generic Magmi Engine", "version" => "1.1", "author" => "dweeves");
}

/**
Expand Down Expand Up @@ -278,6 +278,11 @@ public function getPluginInstance($family, $order = -1)
if ($order < 0) {
$order += count($this->_activeplugins[$family]);
}






if (is_array($this->_activeplugins) && isset($this->_activeplugins[$family]) && isset($this->_activeplugins[$family][$order])) {
return $this->_activeplugins[$family][$order];
Expand Down Expand Up @@ -310,7 +315,7 @@ public function callPlugins($types, $callback, &$data = null, $params = null, $b
if (isset($this->_activeplugins[$ptype])) {
// For all instances in the family
foreach ($this->_activeplugins[$ptype] as $pinst) {
$pclass=get_class($pinst);
$pclass = get_class($pinst);
// If the plugin has a hook for the defined processing step
if (method_exists($pinst, $callback)) {
// Timing initialization for current plugin in processing step
Expand Down Expand Up @@ -417,11 +422,11 @@ public function getExceptionTrace($tk, &$traces)
}
}
if (!isset($this->_exceptions[$tk])) {
$this->_exceptions[$tk] = array(0,$this->_excid);
$this->_exceptions[$tk] = array(0, $this->_excid);
}
$this->_exceptions[$tk][0]++;
$trstr = "************************************\n$tk\n*************************************\n$trstr";
return array($trstr,$this->_exceptions[$tk][0] == 1,$this->_exceptions[$tk][1]);
return array($trstr, $this->_exceptions[$tk][0] == 1, $this->_exceptions[$tk][1]);
}

public function trace($e, $data = "")
Expand Down Expand Up @@ -505,7 +510,7 @@ public function connectToMagento()
$socket = $this->getProp("DATABASE", "unix_socket");
if ($conn == 'localxml') {
$baseDir = $this->getProp('MAGENTO', 'basedir');
$xmlPath = $baseDir.'/app/etc/local.xml';
$xmlPath = $baseDir . '/app/etc/local.xml';
if (!file_exists($xmlPath)) {
throw new Exception("Cannot load xml from path '$xmlPath'");
}
Expand All @@ -516,6 +521,18 @@ public function connectToMagento()
$user = $default_setup->username;
$pass = $default_setup->password;
$port = $default_setup->port;
} else if ($conn === 'envphp') {
$envPath = dirname(__FILE__) . "/../../app/etc/env.php";
if (!file_exists($envPath)) {
throw new Exception("Cannot load xml from path '$envPath'");
}
$env_array = include $envPath;
$host_array = explode(":",$env_array['db']['connection']['default']['host']);
$host = $host_array[0];
$port = isset($host_array[1]) ? $host_array[1] : '3306';
$dbname = $env_array['db']['connection']['default']['dbname'];
$user = $env_array['db']['connection']['default']['username'];
$pass = $env_array['db']['connection']['default']['password'];
} else {
$host = $this->getProp("DATABASE", "host", "localhost");
$dbname = $this->getProp("DATABASE", "dbname", "magento");
Expand All @@ -528,6 +545,7 @@ public function connectToMagento()
$this->_db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
}
}

/*
* Disconnect Magento db
*/
Expand Down
1 change: 1 addition & 0 deletions magmi/web/magmi_config_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class="saveinfo">
<?php
}?>
<option value="localxml" <?php echo $curconn == "localxml" ? 'selected="selected"' : '' ?>>Using magento.xml</option>
<option value="envphp" <?php echo $curconn == "envphp" ? 'selected="selected"' : '' ?>>Using env.php</option>
</select></li>
</ul>

Expand Down

0 comments on commit 9681a4e

Please sign in to comment.