Browse Source

Add demo contacts generator

quickform
Paweł Jedwabny 4 years ago
parent
commit
5326941896
4 changed files with 162 additions and 3 deletions
  1. +2
    -1
      composer.json
  2. +50
    -2
      composer.lock
  3. +1
    -0
      console.php
  4. +109
    -0
      console/Demo/GenerateContactsCommand.php

+ 2
- 1
composer.json View File

@@ -4,7 +4,8 @@
"twig/twig": "^1.24",
"symfony/console": "^2.7",
"symfony/http-foundation": "^2.7",
"phpdocumentor/reflection-docblock": "^2.0.4"
"phpdocumentor/reflection-docblock": "^2.0.4",
"fzaninotto/faker": "^1.6"
},
"scripts": {
"post-install-cmd": [


+ 50
- 2
composer.lock View File

@@ -4,10 +4,58 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "5351ab59fd20fec1fe517dba597a09fd",
"content-hash": "dd13d59541b6ce113cd2a165874516d0",
"hash": "805a72a4fb5bc94bbc7bc7ef46685f73",
"content-hash": "a637abf974de6f43d7f8d88e92c63cdc",
"packages": [
{
"name": "fzaninotto/faker",
"version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"shasum": ""
},
"require": {
"php": "^5.3.3|^7.0"
},
"require-dev": {
"ext-intl": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"type": "library",
"extra": {
"branch-alias": []
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"time": "2016-04-29 12:21:54"
},
{
"name": "ircmaxell/password-compat",
"version": "v1.0.4",
"source": {


+ 1
- 0
console.php View File

@@ -23,4 +23,5 @@ $application->add(new \Epesi\Console\Maintenance\MaintenanceOnCommand());
$application->add(new \Epesi\Console\Maintenance\MaintenanceOffCommand());
$application->add(new \Epesi\Console\SearchClearCommand());
$application->add(new \Epesi\Console\SearchIndexCommand());
$application->add(new \Epesi\Console\Demo\GenerateContactsCommand());
$application->run();

+ 109
- 0
console/Demo/GenerateContactsCommand.php View File

@@ -0,0 +1,109 @@
<?php

namespace Epesi\Console\Demo;

use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;

class GenerateContactsCommand extends Command
{
protected function configure()
{
$this
->setName('demo:generate:contacts')
->setDescription('Generate demo contacts')
->addOption('create-user', null, InputOption::VALUE_NONE, 'Create user')
->addOption('create-company', null, InputOption::VALUE_NONE, 'Create company related to contact')
->addOption('count', null, InputOption::VALUE_REQUIRED, 'Count of generated records');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
\Variable::set('anonymous_setup', 1);
$count = $input->getOption('count') ?: 1;

$progress = new ProgressBar($output, $count);

$table = new Table($output);
$headers = array(
'<fg=white;options=bold>Id</fg=white;options=bold>',
'<fg=white;options=bold>First Name</fg=white;options=bold>',
'<fg=white;options=bold>Last Name</fg=white;options=bold>'
);

if($input->getOption('create-company')){
$headers[] = '<fg=white;options=bold>Company</fg=white;options=bold>';
}

if($input->getOption('create-user')) {
$headers[] = '<fg=white;options=bold>Login</fg=white;options=bold>';
$headers[] = '<fg=white;options=bold>Password</fg=white;options=bold>';
}

$table->setHeaders($headers);


$progress->start();
for ($i = 0; $i < $count; $i++) {
$faker = \Faker\Factory::create();
$values = [];
$values['submited'] = '';
$values['last_name'] = $faker->lastName;
$values['first_name'] = $faker->firstName;
$values['country'] = $faker->countryCode;
$values['permission'] = 0;
$values['title'] = $faker->title;
$values['work_phone'] = $faker->phoneNumber;
$values['mobile_phone'] = $faker->phoneNumber;
$values['fax'] = $faker->phoneNumber;
$values['email'] = $faker->email;
$values['web_address'] = $faker->url;
$values['address_1'] = $faker->streetAddress;
$values['address_2'] = $faker->streetAddress;
$values['city'] = $faker->city;
$values['postal_code'] = $faker->postcode;
$values['home_phone'] = $faker->phoneNumber;
$values['home_address_1'] = $faker->streetAddress;
$values['home_address_2'] = $faker->streetAddress;
$values['home_city'] = $faker->city;
$values['home_country'] = $faker->countryCode;
$values['home_postal_code'] = $faker->postcode;
$values['birth_date'] = $faker->dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = date_default_timezone_get())->format('Y-m-d');

$row = [$values['first_name'], $values['last_name']];



if ($input->getOption('create-company')) {
$values['create_company'] = 1;
$values['create_company_name'] = $faker->company;
$row[] = $values['create_company_name'];
}

if ($input->getOption('create-user')) {
$values['login'] = 'new';
$values['username'] = $faker->userName;
$values['set_password'] = $faker->password;
$values['confirm_password'] = $values['set_password'];
$values['admin'] = 0;
$row[] = $values['username'];
$row[] = $values['set_password'];
}

$id = \Utils_RecordBrowserCommon::new_record('contact', $values);
array_unshift($row, $id);
$table->addRow($row);
$progress->advance();
}
$progress->finish();
$output->write('', true);
$table->render();
}
}

Loading…
Cancel
Save