-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert plugins data dump to seeder (#467)
* convert plugins data dump to seeder * remove plugins sql data * fix laravel lint errors
- Loading branch information
1 parent
c1815d5
commit bccebb0
Showing
11 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
src/backend/database/dummyData/bulk-registration-template-1.hex
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
src/backend/database/dummyData/bulk-registration-template-2.hex
Large diffs are not rendered by default.
Oops, something went wrong.
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,23 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Inensus\CalinMeter\Models\CalinCredential; | ||
|
||
class CalinCredentialFactory extends Factory { | ||
protected $model = CalinCredential::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'api_url' => 'http://api.calinhost.com/api', | ||
'user_id' => 'Inensus'.$this->faker->randomNumber(1, 100), | ||
'api_key' => '123123', | ||
]; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Inensus\BulkRegistration\Models\CsvData; | ||
|
||
class CsvDataFactory extends Factory { | ||
protected $model = CsvData::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'user_id' => $this->faker->randomNumber(1, 10), | ||
'csv_filename' => 'bulk_registration'.$this->faker->randomNumber(1, 4).'csv', | ||
'csv_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,22 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Plugins; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class PluginsFactory extends Factory { | ||
protected $model = Plugins::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'mpm_plugin_id' => $this->faker->randomNumber(1, 15), | ||
'status' => 1, | ||
]; | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/backend/database/factories/WaveMoneyCredentialFactory.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,26 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Inensus\WaveMoneyPaymentProvider\Models\WaveMoneyCredential; | ||
|
||
class WaveMoneyCredentialFactory extends Factory { | ||
protected $model = WaveMoneyCredential::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() { | ||
return [ | ||
'merchant_id' => 'MERCHANT ID '.$this->faker->randomNumber(1, 100), | ||
'merchant_name' => 'Demo Merchant', | ||
'secret_key' => '123123', | ||
'callback_url' => 'https://staging.micropowermanager.com/api/wave-money/wave-money-transaction/callback/11', | ||
'payment_url' => 'https://staging.micropowermanager.com/api/wave-money/payment/Demo Merchant/11', | ||
'result_url' => 'https://staging.micropowermanager.com/api/wave-money/wave-money-transaction/result/Demo Merchant/11', | ||
]; | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\Plugins; | ||
use Database\Factories\CalinCredentialFactory; | ||
use Database\Factories\CsvDataFactory; | ||
use Database\Factories\WaveMoneyCredentialFactory; | ||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\DB; | ||
use MPM\DatabaseProxy\DatabaseProxyManagerService; | ||
|
||
class PluginsSeeder extends Seeder { | ||
public function __construct( | ||
private DatabaseProxyManagerService $databaseProxyManagerService, | ||
) { | ||
$this->databaseProxyManagerService->buildDatabaseConnectionDummyCompany(); | ||
} | ||
|
||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() { | ||
$this->generatePlugins(); | ||
} | ||
|
||
private function generatePlugins() { | ||
Plugins::factory()->count(10)->create(); | ||
$this->generateBulkRegistrationCsvData(); | ||
$this->generateCalinCredential(); | ||
$this->generateWaveMoneyCredential(); | ||
} | ||
|
||
private function generateBulkRegistrationCsvData() { | ||
$factory = new CsvDataFactory(); | ||
$dummyDataPath = database_path('dummyData'); | ||
|
||
// Get the contents of the CSV files as arrays | ||
$csvFiles = [ | ||
$dummyDataPath.'/bulk-registration-template-1.hex', | ||
$dummyDataPath.'/bulk-registration-template-2.hex', | ||
]; | ||
$csvData = []; | ||
|
||
foreach ($csvFiles as $csvFile) { | ||
if (file_exists($csvFile)) { | ||
// Read the entire CSV file content as a string | ||
$csvData[] = file_get_contents($csvFile); | ||
} else { | ||
throw new \Exception('CSV file not found: '.$csvFile); | ||
} | ||
} | ||
|
||
foreach ($csvData as $data) { | ||
$factory->create([ | ||
'csv_data' => DB::raw("X'{$data}'"), | ||
]); | ||
} | ||
} | ||
|
||
private function generateCalinCredential($count = 2) { | ||
(new CalinCredentialFactory())->count($count)->create(); | ||
} | ||
|
||
private function generateWaveMoneyCredential($count = 2) { | ||
(new WaveMoneyCredentialFactory())->count($count)->create(); | ||
} | ||
} |