Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"homepage": "https://github.com/voycey/cakephp-salesforce",
"license": "MIT",
"require": {
"php": ">=5.4.16",
"cakephp/cakephp": "~3.0",
"php": ">=7.4",
"cakephp/cakephp": "^4.0",
"ae/salesforce-rest-sdk": "^2.0",
"developerforce/force.com-toolkit-for-php": "^1.0@dev"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use Cake\Cache\Cache;

Cache::config('salesforce', [
Cache::setConfig('salesforce', [
'className' => 'Cake\Cache\Engine\FileEngine',
'duration' => '+1 hours',
'probability' => 100,
'path' => CACHE . 'salesforce' . DS,
]);

?>
?>
8 changes: 5 additions & 3 deletions src/Database/Dialect/SalesforceDialectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Salesforce\Database\Dialect;

use Cake\Database\Schema\SchemaDialect;
use Salesforce\Database\Schema\SalesforceSchema;
use Cake\Database\SqlDialectTrait;

Expand Down Expand Up @@ -57,7 +59,7 @@ trait SalesforceDialectTrait
*
* @return \Cake\Database\Schema\MysqlSchema
*/
public function schemaDialect()
public function schemaDialect(): SchemaDialect
{
if (!$this->_schemaDialect) {
$this->_schemaDialect = new SalesforceSchema($this);
Expand All @@ -68,15 +70,15 @@ public function schemaDialect()
/**
* {@inheritDoc}
*/
public function disableForeignKeySQL()
public function disableForeignKeySQL(): string
{
return '';
}

/**
* {@inheritDoc}
*/
public function enableForeignKeySQL()
public function enableForeignKeySQL(): string
{
return '';
}
Expand Down
103 changes: 68 additions & 35 deletions src/Database/Driver/Salesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Salesforce\Database\Driver;

use AE\SalesforceRestSdk\AuthProvider\CachedSoapProvider;
use AE\SalesforceRestSdk\Rest\Client;
use Cake\Database\Query;
use Cake\Database\QueryCompiler;
use Cake\Database\StatementInterface;
use Cake\Database\ValueBinder;
use Cake\Filesystem\File;
use Salesforce\Database\Dialect\SalesforceDialectTrait;
use Salesforce\Database\Driver\SalesforceDriverTrait;
use Salesforce\Database\SalesforceQueryCompiler;
use Salesforce\Database\SalesforceQuery;
use Salesforce\Database\Statement\SalesforceStatement;
use Cake\Database\Driver;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class Salesforce extends Driver
{
Expand All @@ -46,73 +53,66 @@ class Salesforce extends Driver
'init' => [],
];

/**
* Establishes a connection to the database server
*
* @return bool true on success
*/
public function connect()
{
if ($this->_connection) {
return true;
}
$config = $this->_config;

$this->_connect($config);

if (!empty($config['init'])) {
$connection = $this->connection();
foreach ((array)$config['init'] as $command) {
$connection->exec($command);
}
}
return true;
}

/**
* Returns whether php is able to use this driver for connecting to database
*
* @return bool true if it is valid to use this driver
*/
public function enabled()
public function enabled(): bool
{
return true; //Dont know if I need this?
return true;
}

/**
* Prepares a sql statement to be executed
*
* @param string|\Cake\Database\Query $query The query to prepare.
* @return \Cake\Database\StatementInterface
* @throws \ErrorException
*/
public function prepare($query)
public function prepare($query): StatementInterface
{
$this->connect();
$isObject = $query instanceof SalesforceQuery;
//$statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
$result = new SalesforceStatement($query, $this);
if ($isObject && $query->bufferResults() === false) {
if ($isObject && $query->isBufferedResultsEnabled() === false) {
$result->bufferResults(false);
}

return $result;
}

/**
* {@inheritDoc}
* Establishes a connection to the database server
*
* @return bool true on success
* @throws \ErrorException
*/
public function supportsDynamicConstraints()
public function connect(): bool
{
if ($this->_connection) {
return true;
}
$config = $this->_config;

$this->_connect('', $config);

if (!empty($config['init'])) {
$connection = $this->connection();
foreach ((array)$config['init'] as $command) {
$connection->exec($command);
}
}
return true;
}

/**
* Returns an instance of a QueryCompiler
*
* @return \Cake\Database\QueryCompiler
* {@inheritDoc}
*/
public function newCompiler()
public function supportsDynamicConstraints(): bool
{
return new SalesforceQueryCompiler;
return true;
}

/**
Expand All @@ -124,11 +124,44 @@ public function newCompiler()
* @return array containing 2 entries. The first entity is the transformed query
* and the second one the compiled SQL
*/
public function compileQuery(Query $query, ValueBinder $generator)
public function compileQuery(Query $query, ValueBinder $generator): array
{
$processor = $this->newCompiler();
$translator = $this->queryTranslator($query->type());
$query = $translator($query);
return [$query, $processor->compile($query, $generator)];
}

/**
* Returns an instance of a QueryCompiler
*
* @return SalesforceQueryCompiler
*/
public function newCompiler(): QueryCompiler
{
return new SalesforceQueryCompiler();
}

protected $restClient;

public function getRestClient()
{
$wsdl = new File(CONFIG . $this->_config['my_wsdl']);
$res = preg_match('#soap:address location="(https://.*)/services/Soap/c/(\d+.\d)#', $wsdl->read(), $matches);
if ($this->restClient === null) {
$this->restClient = new Client(
new CachedSoapProvider(
new FilesystemAdapter('', 0, CACHE),
$this->_config['username'],
$this->_config['password'],
$matches[1]
),
$matches[2]
);

}

return $this->restClient;
}

}
Loading