Prestashop 1.7 - Get Database parameters - php

Situation: I need to get the parameters of the database from one PrestaShop 1.7, i know that are in parameters.php but i dont know how to get it in another .php.
The code of parameters.php are the following.
How i get the parameters??
Thanks.
<?php return array (
'parameters' =>
array (
'database_host' => '127.0.0.1',
'database_port' => '',
'database_name' => '',
'database_user' => '',
'database_password' => '',
'database_prefix' => 'ps_',
'database_engine' => 'InnoDB',
'mailer_transport' => 'smtp',
'mailer_host' => '127.0.0.1',
'mailer_user' => NULL,
'mailer_password' => NULL,
'secret' => 'fIz1vXGf14HQP0gYIGSOv3yqWAswhTLQ6JRAvCnAytNUUJgVOoHWYhip',
'ps_caching' => 'CacheMemcache',
'ps_cache_enable' => false,
'ps_creation_date' => '2017-10-09',
'locale' => 'es-ES',
'cookie_key' => '457GbAM3q5ctnvb0wjyyVcuNO0SfzFFxZghNSKW2TWhc9GfzPSvKDAQc',
'cookie_iv' => 'RvcXmr9J',
'new_cookie_key' => 'def00000ce15b57d4b2e1cdb214464708c3fefc4145607fff1400890a08aa234e5b5c7b0061a1af4647cbdf668ad9f383739c95f710f0e3d606d0e07dc11c20e42d6f0ec',
),
);

You can try this
$config = require _PS_CACHE_DIR_ . 'appParameters.php';
var_dump($config['parameters']['database_host']);

Related

Identifying unknown structured data formats – what could be class-oriented JSON

I'm currently working with a Sophos UTM, pushing the wireless statistics to another platform and trying to digest this data format.
It's clearly structured and looks like class-oriented JSON, but cannot quite figure out what it is or how to convert it to something usable. Any ideas? I thought about just writing a JSON-converter in PHP, but I'm afraid that I might just be missing a puzzle piece.
{
'clients' => {
'0c:2c:54:xx:xx:xx' => {
'ap' => '',
'connected_time_sec' => 1720,
'connected_time_str' => '00:28:40',
'hwaddr' => '0c:2c:54:xx:xx:xx',
'ip' => '172.16.28.206',
'last_rxrate_bps' => '1048576',
'last_rxrate_str' => '1024.0 kbit/s',
'last_txrate_bps' => '6815744',
'last_txrate_str' => '6.5 Mbit/s',
'lastseen_str' => '2018-11-04 18:06:37',
'lastseen_ts' => 1541351197,
'mesh_id' => '',
'mesh_mode' => 'none',
'name' => 'HUAWEI_P20_Pro',
'radio_id' => '0',
'signal_per' => '39',
'ssid' => 'ssid',
'vendor' => 'unknown'
},
'44:d8:84:xx:xx:xx' => {
'ap' => 'A40001AXX8FXXXX',
'connected_time_sec' => 534992,
'connected_time_str' => '06:04:36:32',
'hwaddr' => '44:d8:84:xx:xx:xx',
'ip' => '172.16.28.149',
'last_rxrate_bps' => '1048576',
'last_rxrate_str' => '1024.0 kbit/s',
'last_txrate_bps' => '60607488',
'last_txrate_str' => '57.8 Mbit/s',
'lastseen_str' => '2018-11-04 20:44:28',
'lastseen_ts' => 1541360668,
'mesh_id' => '',
'mesh_mode' => 'none',
'name' => 'iMac-OBC',
'radio_id' => '0',
'signal_per' => '65',
'ssid' => 'ssid',
'vendor' => 'Apple'
}
},
'connected' => {
'A40001AXX8FXXXX' => {
'associated_clients' => [
'ab:cd:ef:gh:ij:kl',
'44:d8:84:xx:xx:xx',
],
'bss' => undef,
'id' => 'A40001AXX8FXXXX',
'ip' => '192.168.10.11',
'lan_mac' => '00:1a:8c:xx:xx:xx',
'location' => 'AP30',
'type' => 'AP30',
'wifi_mac' => '00:1a:8c:xx:xx:xx'
},
'A4000EASIJDFSDOI' => {
'associated_clients' => [],
'bss' => undef,
'id' => 'A4000EASIJDFSDOI',
'ip' => '192.168.10.12',
'lan_mac' => '00:1a:8c:xx:xx:xx',
'location' => 'AP30',
'type' => 'AP30',
'wifi_mac' => '00:1a:8c:xx:xx:xx'
}
},
'disconnected' => {},
'lastupdate' => 1541360678
}
Your sample data has 4 repairs to make on the road to valid json town.
Make the following replacements:
=> to :
' to "
remove all trailing , that are followed by zero or more whitespace characters then a ]
wrap your undef values in double quotes
Code: (Demo)
$almostjson = <<<ALMOSTJSON
...your input string
ALMOSTJSON;
$json = preg_replace(["~=>~", "~'~", "~,(?=\s*])~", "~:\s+\Kundef~"], [':', '"', '', '"$0"'], $almostjson);
var_export(json_decode($json, true));
Calling regex functions on strings that contain key-value relationships is vulnerable to unintended matching. This "solution" should be considered a "bandaid" until the source of the data can be improved. This solution may silently fail in the future if the wrong quality of text is in the string.

Array into a PHP Soapclient call

I'm using php and Soapclient. I need send next parameters:
<sch:CodConsulta v="5473"/>
<sch:Parametros>
<sch:Txt n="Agente" v="aaa"/>
<sch:Fec n="Fecha" v="2018-01-24"/>
<sch:Txt n="Sesion" v="0"/>
</sch:Parametros>
I've tried send params like this:
$parametros = array(
"CodConsulta" => array('_' => '',"v" => "5473"),
"Parametros" => array(
"Txt" => array('_' => '',"n" => "Agente","v" => "aaa"),
"Fec" => array('_' => '',"n" => "Fecha","v" => "2018-01-24"),
"Txt" => array('_' => '',"n" => "Sesion","v" => "0")
)
);
Webservice return error, only receive 1 param...
Any help would be much appreciated. Thanks in advance.

SugarCRM On-Demand Convert TextField to DropDown

A similar question was posted here before but it only applied to an On-Site SugarCRM instance (it was also a long time ago).
In my case I would like to change the "Billing Country" field from 'TextField' to 'DropDdown' on an On-Demand instance where I don't have access to the config files. How can I do this?
So far I have tried different PHP files using the Module Loader but it's not working either.
Please find my PHP script below:
<?php
$manifest = array(
'acceptable_sugar_flavors' => array('CE', 'PRO', 'CORP', 'ENT', 'ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
0 => '6\\.5\\.(.*?)',
1 => '6\\.7\\.(.*?)',
2 => '7\\.2\\.(.*?)',
3 => '7\\.2\\.(.*?)\\.(.*?)',
4 => '7\\.5\\.(.*?)\\.(.*?)',
5 => '7\\.6\\.(.*?)\\.(.*?)'
),
),
'name' => 'Textfield to Dropdown',
'description' => 'Converting Billing Country textfield to Dropdown Field',
'author' => 'myname',
'icon' => '',
'is_uninstallable' => true,
'published_date' => '2015-01-09 19:00:00',
'type' => 'module',
'version' => '1.0',
);
$dictionary['Account']['fields']['billing_address_country']['type'] = 'enum';
$dictionary['Account']['fields']['billing_address_country']['ext1'] = 'countries_dom';
The module loads fine but there's no change after a Quick Repair. I have tried with the following variables, as well:
$dictionary['Account']['fields']['billing_address_country']['isDropDown']=yes;
and...
$dictionary['Account']['fields']['billing_address_country']['Options']='countries_dom';
Can anyone tell me what I am doing wrong? I'd appreciate any help or guidance you have. Please advise.
Cheers,
H
P.S. I am using SugarCRM On-Demand Version 7.6.1
You need to create the manifest.php file and have that point to the file(s) you want to copy/upload for customization:
manifest.php:
<?php
$manifest = array(
'built_in_version' => '7.6.1.0',
'acceptable_sugar_versions' =>
array(
0 => '',
),
'acceptable_sugar_flavors' =>
array(
0 => 'PRO',
1 => 'CORP',
2 => 'ENT',
3 => 'ULT',
),
'readme' => '',
'key' => 'SO',
'author' => 'Eric',
'description' => 'Convert Accounts Billing Country TextField to Enum',
'icon' => '',
'is_uninstallable' => true,
'name' => 'TextFieldToDropdownPkg',
'published_date' => '2016-01-10 03:01:01',
'type' => 'module',
'version' => 1452378413,
'remove_tables' => 'prompt',
);
$installdefs = array(
'id' => 'TextFieldToDropdownPkg',
'copy' => array(
0 => array(
'from' => '<basepath>/custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
'to' => 'custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
),
),
);
Then create:
custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php
<?php
$dictionary['Account']['fields']['billing_address_country']['comments']='Country for primary address';
$dictionary['Account']['fields']['billing_address_country']['group']='primary_address';
$dictionary['Account']['fields']['billing_address_country']['options']='countries_dom';
$dictionary['Account']['fields']['billing_address_country']['type']='enum';
ZIP those files up and use Module Loader.

CakePHP find all not setting values to variables. All other find functions working

In my controller I have two functions that pull all records from the db with a status = 4. In one function it works fine. I copied the find all statement from the working function:
$this->set('completed', $this->Topic->find('all', array('fields' => array(
'Topic.creator','Topic.link','Topic.id', 'Topic.topic_name', 'Topic.info', 'Topic.priority', 'Topic.user_id',
'Topic.completed','Topic.created', 'Topic.status','User.name','User.id','Topic.category','Topic.tags'),'conditions' => array(
'Topic.status' => 4))));
But in the new function the $completed array doesn't seem to exist. The debug statement is just a blank line. If I debug the sql log using debug($this->Topic->getDataSource()->getLog()); this is the returned array:
Array
(
[log] => Array
(
[0] => Array
(
[query] => SELECT `Topic`.`creator`, `Topic`.`link`, `Topic`.`id`, `Topic`.`topic_name`, `Topic`.`info`, `Topic`.`priority`, `Topic`.`user_id`, `Topic`.`completed`, `Topic`.`created`, `Topic`.`status`, `User`.`name`, `User`.`id`, `Topic`.`category`, `Topic`.`tags` FROM `topics` AS `Topic` LEFT JOIN `users` AS `User` ON (`Topic`.`user_id` = `User`.`id`) LEFT JOIN `events` AS `Event` ON (`Event`.`topic_id` = `Topic`.`id`) WHERE `Topic`.`status` = 4
[affected] => 9
[numRows] => 9
[took] => 0
)
)
[count] => 1
[time] => 0
)
The SQL statement in the log works. If I plug in into mySQL it produces results. And the affected and numRows field show the correct number of records. But the produced data isn't being set to variables. Any ideas would be greatly appreciated. My boss and I are stumped. Here are both complete functions:
public function dashboard(){
$this->set('completed', $this->Topic->find('all', array('fields' => array(
'Topic.creator','Topic.link','Topic.id', 'Topic.topic_name', 'Topic.info', 'Topic.priority', 'Topic.user_id',
'Topic.completed','Topic.created', 'Topic.status','User.name','User.id','Topic.category','Topic.tags'),'conditions' => array(
'Topic.status' => 4))));
$this->set('total_inprogress_release', $this->Topic->find('count', array('conditions' => array(
'OR' => array('status <>' => 4,'status <>' => 0),
'priority' => 4))));
$this->set('upcoming_events', $this->Topic->Event->find('all'));
$this->Topic->virtualFields['count'] = 'COUNT(*)';
$this->set('graph_data', $this->Topic->find('chart', array('fields' => array('status_txt', 'priority_txt', 'count'), 'group' => array('status', 'priority'),
'chart' => array(
'xaxisTitle' => 'Status',
'yaxisLabels' => array('Release', 'Company', 'News'),
'xaxisLabels' => array('Open','In Progress','Completed'),
'yaxis' => 'Topic.priority_txt',
'xaxis' => 'Topic.status_txt',
'data' => 'Topic.count'
))));
}
And here's the nonworking function:
public function completed(){
$foo = $this->Topic->find('all', array('fields' => array(
'Topic.creator','Topic.link','Topic.id', 'Topic.topic_name', 'Topic.info', 'Topic.priority', 'Topic.user_id',
'Topic.completed','Topic.created', 'Topic.status','User.name','User.id','Topic.category','Topic.tags'),'conditions' => array(
'Topic.status' => 4)));
debug($foo);
debug($this->Topic->getDataSource()->getLog());
}
After several hours of tracking the data until we figured out where it was being lost, we found that the problem was some of the data in the database. It was encoded and it was causing a while statement in the core cake files to reset when it encountered said data. The solution was to alter Config/database.php as such:
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'login',
'password' => 'Password',
'database' => 'database',
'prefix' => '',
'encoding' => 'utf8',//this line allows the database to read utf8 data.
);
}
I think the relationships may be causing an issue here. Try this in the completed function and pr($foo) the results:
$foo = $this->Topic->find('all', array(
'fields' => array(
'Topic.creator',
'Topic.link',
'Topic.id',
'Topic.topic_name',
'Topic.info',
'Topic.priority',
'Topic.user_id',
'Topic.completed',
'Topic.created',
'Topic.status',
'User.name',
'User.id',
'Topic.category',
'Topic.tags'
),
'conditions' => array(
'Topic.status' => 4,
),
'joins' => array(
array(
'table' => 'users',
'alias' => 'User',
'type' => 'LEFT',
'conditions' => array(
'Topic.user_id = User.id'
),
),
),
'recursive' => -1,
));
I suspect you will get the results you are looking for.

Kohana - Session Database

I'm attempting to use the session database with Kohana 3.
I have setup the mysql database as described here: http://kerkness.ca/wiki/doku.php?id=sessions_and_cookies
I am setting session variables like so:
Session::instance('database')->set('uid', $user_id);
However when I go to fetch the data back later on a different page or refresh it returns NULL.
Session::instance('database')->get('uid', NULL);
But if I put them right next to each other it works fine... i.e.
Session::instance('database')->set('uid', $user_id);
Session::instance('database')->get('uid', NULL);
Any ideas as to why this is happening?
I have also setup session.php in my config folder which looks like this:
<?php
return array(
'cookie' => array(
'name' => 'cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'native' => array(
'name' => 'session',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'group' => 'default',
'table' => 'sessions',
),
);
?>
Cheers,
Thomas.
Update the session.php file to look like this:
<?php
return array(
'cookie' => array(
'name' => 'session_cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'native' => array(
'name' => 'session_native',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'name' => 'session_database',
'group' => 'default',
'table' => 'sessions',
),
);
?>
Problem was by default the sessions are called 'session'.
So I renamed each adapter and it has fixed the issue.

Categories