Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Fix compatibility with FileMaker Server 12.
Browse files Browse the repository at this point in the history
  • Loading branch information
matsuo committed Jul 7, 2012
1 parent b5c779d commit d145d3e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Filemaker.php
Expand Up @@ -197,7 +197,11 @@ public function read(&$model, $queryData = array(), $recursive = null) {
foreach($conditions as $conditionField => $conditionValue) {
$field = $this->parseConditionField($model, $conditionField, 'field');

$this->connection->AddDBParam($field, $conditionValue, isset($operators[$field]) ? $operators[$field] : 'eq');
if(in_array($field, array_merge($this->allowed_parameters, array('-recid')))){
$this->connection->AddDBParam($field, $conditionValue, '');
} else {
$this->connection->AddDBParam($field, $conditionValue, isset($operators[$field]) ? $operators[$field] : 'eq');
}

//add or operator
if($isOr){
Expand Down Expand Up @@ -227,7 +231,11 @@ public function read(&$model, $queryData = array(), $recursive = null) {
// return a found count if requested
if($queryData['fields'] == 'COUNT') {
// perform find without returning result data
$fmResults = $this->connection->FMFind(true, 'basic');
if(empty($queryData['conditions'])) {
$fmResults = $this->connection->FMFindAll(true, 'basic');
} else {
$fmResults = $this->connection->FMFind(true, 'basic');
}

// test result
if(!$this->handleFXResult($fmResults, $model->name, 'read (count)')) {
Expand All @@ -241,7 +249,11 @@ public function read(&$model, $queryData = array(), $recursive = null) {
return $countResult;
} else {
// perform the find in FileMaker
$fmResults = $this->connection->FMFind();
if(empty($queryData['conditions'])) {
$fmResults = $this->connection->FMFindAll();
} else {
$fmResults = $this->connection->FMFind();
}

if(!$this->handleFXResult($fmResults, $model->name, 'read')) {
return false;
Expand Down Expand Up @@ -369,7 +381,11 @@ public function delete(&$model, $conditions = null) {
} else {
// must contain a -recid field
foreach($conditions as $field => $value) {
$this->connection->AddDBParam($field, $value, 'eq');
if(in_array($field, array('-recid'))){
$this->connection->AddDBParam($field, $value, '');
} else {
$this->connection->AddDBParam($field, $value, 'eq');
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions unit_testing/Case/Model/Datasource/Database/FilemakerTest.php
Expand Up @@ -203,6 +203,37 @@ public function testCreateFindRecord() {
$this->assertArrayHasKey('-modid', $model->schema());
}

/**
* testCreateFindRecordWithNoFindCriteria method
*
* @return void
*/
public function testCreateFindRecordWithNoFindCriteria() {
$model =& new TestArticle();
$_data = array(
'TestArticle' => array(
'Title' => 'UT CFRWNFC Title',
'Body' => 'UT CFRWNFC Body'
)
);
$model->create();
$saveResult = $model->save($_data);

$primaryKeyID = $model->id;

$result = $model->find('all', array(
'conditions' => array(),
'recursive' => 0,
));

$this->assertInternalType('array', $result);
$this->assertGreaterThan(0, count($result[0]));
$this->assertEqual($result[0]['TestArticle']['id'], $primaryKeyID);
$this->assertEqual($result[0]['TestArticle']['Title'], 'UT CFRWNFC Title');
$this->assertArrayHasKey('id', $model->schema());
$this->assertArrayHasKey('-recid', $model->schema());
}

/**
* testCreateFindDeleteRecordAll method
*
Expand Down

0 comments on commit d145d3e

Please sign in to comment.