Added Location field to summit metric

Change-Id: Ib8c9f96437e2414ce4d46714f8724330de2dbfc5
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2020-10-16 12:01:23 -03:00
parent 6dbcde8f57
commit 420c42fbe6
4 changed files with 76 additions and 1 deletions

View File

@ -85,6 +85,7 @@ final class OAuth2SummitMetricsApiController extends OAuth2ProtectedController
[
'type' => 'required|string|in:'.implode(",", ISummitMetricType::ValidTypes),
'source_id' => 'sometimes|integer',
'location' => 'sometimes|string',
]);
if ($validation->fails()) {
@ -142,7 +143,7 @@ final class OAuth2SummitMetricsApiController extends OAuth2ProtectedController
[
'type' => 'required|string|in:'.implode(",", ISummitMetricType::ValidTypes),
'source_id' => 'sometimes|integer',
'location' => 'sometimes|string',
]);
if ($validation->fails()) {

View File

@ -58,6 +58,8 @@ final class SummitMetricFactory
public static function populate(SummitMetric $metric, array $data):SummitMetric{
if(isset($data['type']))
$metric->setType($data['type']);
if(isset($data['location']))
$metric->setLocation(urldecode($data['location']));
return $metric;
}
}

View File

@ -69,6 +69,12 @@ class SummitMetric extends SilverstripeBaseModel
*/
protected $origin;
/**
* @ORM\Column(name="Location", type="string")
* @var string|null
*/
protected $location;
/**
* @ORM\Column(name="Browser", type="string")
* @var string|null
@ -231,4 +237,21 @@ class SummitMetric extends SilverstripeBaseModel
{
return $this->browser;
}
/**
* @return string|null
*/
public function getLocation(): ?string
{
return $this->location;
}
/**
* @param string|null $location
*/
public function setLocation(?string $location): void
{
$this->location = $location;
}
}

View File

@ -0,0 +1,49 @@
<?php namespace Database\Migrations\Model;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\Migrations\Schema\Builder;
use LaravelDoctrine\Migrations\Schema\Table;
/**
* Class Version20201016145706
* @package Database\Migrations\Model
*/
class Version20201016145706 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SummitMetric") && !$builder->hasColumn("SummitMetric","Location") ) {
$builder->table('SummitMetric', function (Table $table) {
$table->text('Location')->setDefault(null)->setNotnull(false);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SummitMetric") && $builder->hasColumn("SummitMetric","Location") ) {
$builder->table('SummitMetric', function (Table $table) {
$table->dropColumn('Location');
});
}
}
}