EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/ https://epe.si
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchIndexCommand.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Epesi\Console;
  3. use Symfony\Component\Console\Command\Command;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use Symfony\Component\Console\Style\SymfonyStyle;
  8. class SearchIndexCommand extends Command
  9. {
  10. protected function configure()
  11. {
  12. $this
  13. ->setName('search:index')
  14. ->setDescription('Index records')
  15. ->addArgument(
  16. 'recordset',
  17. InputArgument::OPTIONAL,
  18. 'Recordset name'
  19. );
  20. }
  21. protected function execute(InputInterface $input, OutputInterface $output)
  22. {
  23. $st = new SymfonyStyle($input, $output);
  24. $recordset = $input->getArgument('recordset');
  25. $recordsets = \DB::GetAssoc('SELECT tab, tab FROM recordbrowser_table_properties WHERE search_include>0');
  26. if ($recordset && !isset($recordsets[$recordset])) {
  27. $st->error('Invalid recordset.');
  28. $st->writeln('Use one of the following:');
  29. $st->listing($recordsets);
  30. return;
  31. }
  32. if ($recordset) {
  33. $recordsets = array($recordset);
  34. }
  35. // count total
  36. $st->writeln("Counting total records to index...");
  37. $total = $this->getTotal($recordsets);
  38. if (!$total) {
  39. $st->writeln('Nothing to index!');
  40. return;
  41. }
  42. $st->writeln("Records count: $total");
  43. $st->writeln("Indexing...");
  44. $st->progressStart($total);
  45. do {
  46. $indexed = 0;
  47. \Utils_RecordBrowserCommon::indexer(500, $indexed);
  48. $st->progressAdvance($indexed);
  49. } while ($indexed);
  50. $st->progressFinish();
  51. $st->writeln("done!");
  52. }
  53. private function getTotal($recordsets)
  54. {
  55. $total = 0;
  56. foreach ($recordsets as $recordset) {
  57. $total += \DB::GetOne("SELECT count(*) FROM {$recordset}_data_1 WHERE active=1 AND indexed=0");
  58. }
  59. return $total;
  60. }
  61. }