Skip to content

Commit

Permalink
Laravel 5 preparation - update text, js
Browse files Browse the repository at this point in the history
  • Loading branch information
briff committed Oct 20, 2015
1 parent 7c1cebd commit 7f81960
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 75 deletions.
33 changes: 0 additions & 33 deletions app/Console/Commands/Inspire.php

This file was deleted.

48 changes: 24 additions & 24 deletions app/Console/Commands/UpdateTextsCommand.php
@@ -1,6 +1,15 @@
<?php

namespace SzentirasHu\Console\Commands;

use App;
use Artisan;
use Cache;
use Config;
use DB;
use Exception;
use Illuminate\Console\Command;
use PHPExcel_Shared_Date;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\Exception\ProcessFailedException;
Expand Down Expand Up @@ -28,11 +37,11 @@ class UpdateTextsCommand extends Command
*/
protected $description = 'Update texts from external source (xls)';
/**
* @var SzentirasHu\Data\Repository\TranslationRepository
* @var TranslationRepository
*/
private $translationRepository;
/**
* @var SzentirasHu\Data\Repository\BookRepository
* @var BookRepository
*/
private $bookRepository;

Expand Down Expand Up @@ -70,6 +79,7 @@ public function fire()
$this->verifyAbbrev($abbrev);

$translation = $this->translationRepository->getByAbbrev($abbrev);
$this->info("Fordítás: {$translation->name} (id: {$translation->id})");

if ($this->option('file') AND $this->option('url')) {
App::abort(500, "A forrást vagy url-el VAGY file névvel lehet megadni. Mindkettővel nem.");
Expand All @@ -79,8 +89,6 @@ public function fire()

$filePath = $this->getFilePath($abbrev);

$books_abbrev2id = $this->getAbbrev2Id($translation);

ini_set('memory_limit', '1024M');

if ($this->option('url')) {
Expand All @@ -91,9 +99,7 @@ public function fire()
App::abort(500, "Nem sikerült fáljt letölteni a megadott url-ről.");
}
try {

file_put_contents($filePath, $raw);

unset($raw);
} catch (Exception $ex) {
App::abort(500, "Nem sikerült a letöltött fájlt elmenteni.");
Expand Down Expand Up @@ -128,15 +134,18 @@ public function fire()
if (empty($row[0])) {
break;
}
$gepi = $row[$columns[$abbrev]['gepi']];
$bookAbbrev2Id = $this->getAbbrev2Id($translation);
$bookNumber = $row[$columns[$abbrev]['gepi']];
$rov = $row[$columns[$abbrev]['rov']];
if (!isset($books_abbrev2id[$rov]) AND ($rov != '-' AND $rov != '')) {
if (!isset($bookAbbrev2Id[$rov]) AND ($rov != '-' AND $rov != '')) {
$badAbbrevs[] = $rov;
} else if ($rov != '-' AND $rov != '') {
$books_gepi2id[$gepi] = $books_abbrev2id[$rov];
$bookNumber2Id[$bookNumber] = $bookAbbrev2Id[$rov];
}
}
if (isset($badAbbrevs)) $this->verifyBadAbbrev($badAbbrevs, $books_abbrev2id);
if (isset($badAbbrevs)) {
App::abort(500, "A következő rövidítések csak a szövegforrásban találhatóak meg, az adatbázisban nem!\n" . implode(', ', $badAbbrevs) . print_r($bookAbbrev2Id, 1));
}

$verseRowIterator = $sheets[$abbrev]->getRowIterator();
$headers = $this->getHeaders($verseRowIterator);
Expand All @@ -158,15 +167,17 @@ public function fire()
else echo fgets($pipes[1], 4096);
}

$inserts = $this->readLines($verseRowIterator, $headers, $fields, $translation, $books_gepi2id, $abbrev, $pipes);
$inserts = $this->readLines($verseRowIterator, $headers, $fields, $translation, $bookNumber2Id, $abbrev, $pipes);

if ($this->hunspellEnabled) {
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($hunspellProcess);

if (isset($hunspellProcess)) {
proc_close($hunspellProcess);
}
}

$reader->close();

if (count($inserts) > 0) {
Expand Down Expand Up @@ -415,17 +426,6 @@ private function verifyBookColumns($konyvoszlopok, $abbrev)
return $konyvoszlopok;
}

/**
* @param $hibasrov
* @param $books_abbrev2id
*/
private function verifyBadAbbrev($hibasrov, $books_abbrev2id)
{
if (isset($hibasrov)) {
App::abort(500, "A következő rövidítések csak a szövegforrásban találhatóak meg, az adatbázisban nem!\n" . implode(', ', $hibasrov) . print_r($books_abbrev2id, 1));
}
}

/**
* @param \Box\Spout\Reader\XLSX\RowIterator $verseRowIterator
* @return array
Expand Down
5 changes: 2 additions & 3 deletions app/Console/Kernel.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use SzentirasHu\Console\Commands\UpdateTextsCommand;

class Kernel extends ConsoleKernel
{
Expand All @@ -13,7 +14,7 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
\SzentirasHu\Console\Commands\Inspire::class,
UpdateTextsCommand::class,
];

/**
Expand All @@ -24,7 +25,5 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
}
}
3 changes: 2 additions & 1 deletion app/Data/Repository/BookRepositoryEloquent.php
Expand Up @@ -6,6 +6,7 @@
namespace SzentirasHu\Data\Repository;


use Cache;
use SzentirasHu\Data\Entity\Book;
use SzentirasHu\Data\Entity\BookAbbrev;

Expand All @@ -14,7 +15,7 @@ class BookRepositoryEloquent implements BookRepository {

public function getBooksByTranslation($translationId)
{
return \Cache::remember('book', 120, function() use ($translationId) {
return Cache::remember('book', 120, function() use ($translationId) {
return Book::where('translation_id', $translationId)->orderBy('id')->get();
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Service/Reference/ReferenceService.php
Expand Up @@ -64,7 +64,7 @@ private function findStoredBookRef($bookRef, $translationId, $refTranslationId =
Log::debug("Book not found in database: {$bookRef->toString()}");
}
} else {
Log:debug("Book not found for abbrev {$bookRef->bookId} in translation {$refTranslationId}");
Log::debug("Book not found for abbrev {$bookRef->bookId} in translation {$refTranslationId}");
}
return $result;
}
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -12,7 +12,11 @@
"twig/extensions": "^1.3",
"gigablah/sphinxphp": "^2.0",
"barryvdh/laravel-ide-helper": "^2.1",
"doctrine/dbal": "^2.5"
"doctrine/dbal": "^2.5",
"endroid/qrcode": "1.2.4",
"imagine/imagine": "~0.5.0",
"box/spout": "~2.0",
"phpoffice/phpexcel": "1.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down

0 comments on commit 7f81960

Please sign in to comment.