-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create migration for unique_key table - Implement functionality for generating unique key in first admin registering time - Add phone number to data that sending to Zapier - Implement functionality for sending created service data to updates - Use guzzle async post request to post created service data to updates.df.com - Add phone number to setup artisan command - Change way to get server ip address - Change endpoint for created services to env - Add checking for / in url - Rename unique_key to instance_id - Move send service data to updates to separate class - Change way to getting instance id - Add checking if instance id exist, and generate if does not exist - Move generating instance id logic to InstanceId model - Add checking if instance id exists in generating instance id method - Remove phone field from df:setup script - Fix issue with generating instance id if it not exist - Fix bug with sending first service if instance id does not exist - Change private method to public
- Loading branch information
1 parent
e3f0f6a
commit 8b84ecd
Showing
6 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
database/migrations/2020_03_02_121555_create_instance_id_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateInstanceIdTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
|
||
Schema::create('instance_id', function (Blueprint $t) { | ||
$t->increments('id'); | ||
$t->string('instance_id'); | ||
$t->timestamp('created_date')->nullable(); | ||
$t->timestamp('last_modified_date')->useCurrent(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('instance_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace DreamFactory\Core\Components; | ||
|
||
use DreamFactory\Core\Models\InstanceId; | ||
use DreamFactory\Core\Utility\Session; | ||
use GuzzleHttp\Exception\RequestException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
|
||
/** | ||
* Class UpdatesSender | ||
* | ||
*/ | ||
|
||
class UpdatesSender { | ||
|
||
/** | ||
* @param $service_type | ||
* | ||
*/ | ||
public static function sendServiceData(string $service_type) { | ||
$updates_endpoint = 'https://updates.dreamfactory.com/api/created-services'; | ||
|
||
if(Session::isAuthenticated()){ | ||
$client = new \GuzzleHttp\Client(); | ||
$client->postAsync($updates_endpoint, [ | ||
'json' => UpdatesSender::gatherServiceAnalyticData($service_type), | ||
'timeout' => 2, | ||
'connect_timeout' => 2 | ||
]) | ||
->then( | ||
function (ResponseInterface $_ignore) {}, | ||
function (RequestException $ex) { | ||
\Log::debug($ex->getMessage()); | ||
} | ||
) | ||
->wait(); | ||
} | ||
} | ||
|
||
/** | ||
* @param $service_type | ||
* | ||
* @return array | ||
*/ | ||
public static function gatherServiceAnalyticData(string $service_type) { | ||
$instance_id = InstanceId::getInstanceIdOrGenerate(); | ||
$email = Session::user()->getAttribute('email'); | ||
|
||
$data = []; | ||
$data['service_type'] = $service_type; | ||
$data['instance_id'] = $instance_id; | ||
$data['ip_address'] = getHostByName(getHostName()); | ||
$data['email'] = $email; | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace DreamFactory\Core\Models; | ||
|
||
class InstanceId extends BaseSystemModel | ||
{ | ||
protected $table = 'instance_id'; | ||
|
||
protected $fillable = ['instance_id']; | ||
|
||
/** | ||
* | ||
* @return string | ||
*/ | ||
public static function getInstanceIdOrGenerate() { | ||
$model = InstanceId::first(); | ||
if(!$model) { | ||
return self::generateInstanceId()->instance_id; | ||
} | ||
return $model['instance_id']; | ||
} | ||
|
||
/** | ||
* | ||
* @return InstanceId | ||
*/ | ||
public static function generateInstanceId() { | ||
$model = new InstanceId([ | ||
'instance_id' => uniqid(), | ||
]); | ||
$model->save(); | ||
|
||
return $model; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters