Skip to content

Instantly share code, notes, and snippets.

@mkeneqa
Created January 29, 2020 00:10
Show Gist options
  • Save mkeneqa/aec9a2805b67f6022fcb7758a6715ff2 to your computer and use it in GitHub Desktop.
Save mkeneqa/aec9a2805b67f6022fcb7758a6715ff2 to your computer and use it in GitHub Desktop.
place in `app/src/Commmand/console_app.php` . Run App with this command: `php bin\console app:add-cols`
<?php
// place in app/src/Commmand/console_app.php
namespace App\Command;
use RedBeanPHP\RedException\SQL;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Helper\Database;
use RedBeanPHP\R as R;
class AddColDataCommand extends command
{
private $_HeadCalCols = array('el 01','el 02','el 03','el 04');
// the name of the command (the part after "bin/console")
protected static $defaultName = 'app:add-cols';
// protected configure()
// {
//
// }
private function InsertHeadCalColoumns(OutputInterface $output)
{
Database::InitConn();
foreach ($this->_HeadCalCols as $col)
{
$record = R::xdispense('sv_headcal_col_def');
$record->short_name = $col;
$record->field_name = $col;
$record->loader = 'HeadCal';
$record->database = 'SV_Head_Calibration';
$record->db_table = 'head_cal';
$record->json_element = 'cal_matrix_json';
try {
$id = R::store($record);
$output->writeln('Inserted Record @ ' . $id);
} catch (SQL $e) {
}
//break;
}
Database::Disconnect();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
//parent::execute($input, $output); // TODO: Change the autogenerated stub
// outputs multiple lines to the console (adding "\n" at the end of each line)
$output->writeln([
'Adding Coloumns',
'============',
'',
]);
$this->InsertHeadCalColoumns($output);
$output->writeln('Cols Insert Complete!');
$output->writeln('BYE!');
return 0;
}
}
@mkeneqa
Copy link
Author

mkeneqa commented Jan 29, 2020

place in: app/src/Commmand/console_app.php .

Run App with this command: php bin\console app:add-cols

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment