Skip to content

Commit

Permalink
chore: work on the places we use the data source label
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisdom Ebong committed Dec 12, 2023
1 parent 2e1abe2 commit 6da5278
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Ushahidi\Modules\V5\Repository\Apikey;
use Ushahidi\Modules\V5\Repository\Webhook;
use Ushahidi\Modules\V5\Repository\HXL;
use Jenssegers\Agent\Agent;

class AppServiceProvider extends ServiceProvider
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"guzzlehttp/guzzle": "^6.5|^7.0.1",
"intercom/intercom-php": "^4.4",
"ircmaxell/password-compat": "^1.0.4",
"jenssegers/agent": "^2.6",
"laravel/framework": "^8.0",
"laravel/passport": "^10.0",
"laravel/tinker": "^2.5",
Expand Down
199 changes: 198 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddMetadataToPostsTable extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$this->table('posts')
->addColumn('metadata', 'json', [
'null' => true,
])
->update();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddSourceToPostsTable extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$this->table('posts')
->addColumn('source', 'text', [
'null' => true,
'after' => 'status'
])
->update();
}
}
1 change: 1 addition & 0 deletions src/Ushahidi/Core/Entity/FormStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function getDefinition()
'sms' => 'int',
'web' => 'int',
'twitter' => 'int',
'mobile' => 'int',
'email' => 'int'
],
];
Expand Down
6 changes: 6 additions & 0 deletions src/Ushahidi/Core/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Post extends StaticEntity
protected $source;
// When originating in an SMS message
protected $contact_id;

protected $metadata;

protected $data_source_message_id;

// StatefulData
Expand All @@ -57,6 +60,7 @@ protected function getDefaultData()
'type' => 'report',
'locale' => 'en_US',
'published_to' => [],
'metadata' => [],
];
}

Expand Down Expand Up @@ -109,6 +113,8 @@ protected function getDefinition()
'completed_stages'=> '*arrayInt',
'sets' => 'array',
'lock' => 'array',
'source' => 'string',
'metadata' => '*json',
'data_source_message_id' => 'string'
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Ushahidi\Modules\V5\Models\Post\Post;
use Ushahidi\Modules\V5\Requests\PostRequest;
use Illuminate\Support\Facades\Auth;
use Jenssegers\Agent\Facades\Agent;
use Ushahidi\Core\Entity\Post as PostEntity;
use Ushahidi\Modules\V5\Models\Stage;

Expand All @@ -28,7 +29,7 @@ class CreatePostCommand implements Command
private $post_content;
private $translations;


// todo: At some point we might want to change it into a parameter
const DEFAULT_LANUGAGE = 'en';
private $availableLanguages;
Expand Down Expand Up @@ -62,6 +63,16 @@ public static function createFromRequest(PostRequest $request): self
$input['locale'] = $request->input('locale') ?? PostEntity::DEFAULT_LOCAL;
$input['base_language'] = $request->input('base_language') ?? PostEntity::DEFAULT_LOCAL;
$input['published_to'] = $request->input('published_to');
if (Agent::isMobile()) {
$input['source'] = 'mobile';
$input['metadata'] = [
'source' => [
'platform' => Agent::platform(),
'browser' => Agent::browser(),
'device' => Agent::device(),
]
];
}
$input['created'] = time();
$input['updated'] = null;

Expand Down
Loading

0 comments on commit 6da5278

Please sign in to comment.