Skip to content

Commit

Permalink
Merge pull request #442 from tdt/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
coreation authored Mar 6, 2017
2 parents d800368 + ffd32e3 commit e3d8573
Show file tree
Hide file tree
Showing 55 changed files with 2,471 additions and 645 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ app/config/workbench.php
public/packages
workbench
node_modules/
app/storage/app

# IDE dependant
.idea
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php
services: mysql
php:
- "5.4"
- "5.6"
- "7.0"
env:
- DB=mysql
before_script:
Expand Down
14 changes: 7 additions & 7 deletions app/Tdt/Core/ContentNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public static function getResponse($data, $extension = null)
$formatter_class = 'Tdt\\Core\\Formatters\\' . $extension . 'Formatter';

// Exception for XML, only XML or HTML is allowed
if ($data->definition['source_type'] == 'XmlDefinition' && !empty($extension) && $data->source_definition['geo_formatted'] != 1) {
if ($extension != "XML" && $extension != "HTML" && $extension != "PHP") {
\App::abort(406, "XML only allows to be formatted in XML, HTML or PHP serialization.");
} elseif ($extension == "XML") {
return self::createXmlResponse($data->data);
}
}
// if ($data->definition['source_type'] == 'XmlDefinition' && !empty($extension) && $data->source_definition['geo_formatted'] != 1) {
// if ($extension != "XML" && $extension != "HTML" && $extension != "PHP") {
// \App::abort(406, "XML only allows to be formatted in XML, HTML or PHP serialization.");
// } elseif ($extension == "XML") {
// return self::createXmlResponse($data->data);
// }
// }

if (empty($extension)) {
$negotiator = new FormatNegotiator();
Expand Down
9 changes: 3 additions & 6 deletions app/Tdt/Core/DataControllers/ELASTICSEARCHController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
use Tdt\Core\Datasets\Data;
use Tdt\Core\Pager;
use Elastica\Client;
use Elastica\Document;
use Elastica\Query\Term;
use Elastica\Search;
use Elastica\Query;
use Elastica\Exception\ResponseException;
use Elastica\Query\SimpleQueryString;
use Elastica\Query\MatchAll;

Expand Down Expand Up @@ -82,9 +79,9 @@ public function readData($source_definition, $rest_parameters = [])
public static function getParameters()
{
$query_params = [
"query" => [
"required" => false,
"description" => "A value that will be used to perform a full text-search on the data."
'query' => [
'required' => false,
'description' => 'A value that will be used to perform a full text-search on the data.'
]
];

Expand Down
31 changes: 15 additions & 16 deletions app/Tdt/Core/DataControllers/MYSQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function readData($source_definition, $rest_parameters = array())
}

// Disregard the paging when rest parameters are given
if (!empty($rest_parameters)) {
if (! empty($rest_parameters)) {
$limit = 500;
$offset = 0;
}
Expand All @@ -54,32 +54,32 @@ public function readData($source_definition, $rest_parameters = array())
$geo[$geo_prop['property']] = $geo_prop['path'];
}

if (!$columns) {
if (! $columns) {
// 500 error because this shouldn't happen in normal conditions
// Columns are parsed upon adding a CSV resource and are always present
\App::abort(500, "Cannot find the columns of the MySQL table file, this might be due to a corrupted database or a broken configuration.");
\App::abort(500, 'Cannot find the columns of the MySQL table file, this might be due to a corrupted database or a broken configuration.');
}

// Create aliases for the columns
$aliases = $this->columnsRepo->getColumnAliases($source_definition['id'], 'MysqlDefinition');
$pk = null;

foreach ($columns as $column) {

if (!empty($column['is_pk'])) {
if (! empty($column['is_pk'])) {
$pk = $column['column_name_alias'];
}
}

// Connect to the database
$db_config = array(
'driver' => 'mysql',
'host' => $source_definition['host'],
'database' => $source_definition['database'],
'username' => $source_definition['username'],
'password' => $source_definition['password'],
'charset' => 'utf8',
'collation' => $source_definition['collation'],
'database' => $source_definition['database'],
'driver' => 'mysql',
'host' => $source_definition['mysql_host'],
'password' => $source_definition['mysql_password'],
'port' => $source_definition['mysql_port'],
'username' => $source_definition['mysql_username'],
);

// Configure a connection
Expand All @@ -92,7 +92,7 @@ public function readData($source_definition, $rest_parameters = array())
$query = $source_definition['query'];

// Get the total amount of records for the query for pagination
preg_match("/select.*?(from.*)/msi", $query, $matches);
preg_match('/select.*?(from.*)/msi', $query, $matches);

if (empty($matches[1])) {
\App::abort(400, 'Failed to make a count statement, make sure the SQL query is valid.');
Expand All @@ -104,20 +104,19 @@ public function readData($source_definition, $rest_parameters = array())

$total_rows = $count_result[0]->count;

if (!$limitInQuery) {
if (!empty($limit)) {
if (! $limitInQuery) {
if (! empty($limit)) {
$query .= ' limit ' . $limit;
}

if (!empty($offset)) {
if (! empty($offset)) {
$query .= ' offset ' . $offset;
}
}

$result = $db->select($query);

} catch (QueryException $ex) {
\App::abort(400, "A bad query has been made, make sure all passed statements are SQL friendly. The error message was: " . $ex->getMessage());
\App::abort(400, 'A bad query has been made, make sure all passed statements are SQL friendly. The error message was: ' . $ex->getMessage());
}

// Get the paging headers
Expand Down
Loading

0 comments on commit e3d8573

Please sign in to comment.