Skip to content

Commit

Permalink
upgrade laravel 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Lefebvre committed Mar 29, 2018
1 parent 235c3f7 commit f98cba2
Show file tree
Hide file tree
Showing 936 changed files with 325,378 additions and 83,083 deletions.
Empty file modified app/Commands/Command.php
100644 → 100755
Empty file.
Empty file modified app/Commands/ImportCorpus.php
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions app/Console/Commands/BatchStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct()
*/
public function handle(CorpusRepository $corpora)
{

$evaluation_corpora = $corpora->getEvaluation();
$scores_init = [0,5,10];
$weights_level = [1,2];
Expand Down
62 changes: 62 additions & 0 deletions app/Console/Commands/CloseDuels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Duel;
use DB;

class CloseDuels extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'duels:close';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Free the duels not completed of more than 14 days';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$duels_to_close = Duel::where('state','in_progress')->whereRaw('DATEDIFF(NOW(), updated_at) > 14')->get();
foreach($duels_to_close as $duel){
$users_completed = array();
$users_in_progress = array();
foreach($duel->users as $user){
if($user->pivot->turn==$duel->nb_turns){
$users_completed[]=$user;
} else {
$users_in_progress[]=$user;
}
}
if($users_completed){
foreach($users_in_progress as $user){
$duel->users()->detach($user->id);
}
$duel->state = 'pending';
$duel->save();
}
}
}
}
4 changes: 2 additions & 2 deletions app/Console/Commands/ComputeStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function handle(CorpusRepository $corpora)
{
$evaluation_corpora = $corpora->getEvaluation();

foreach($evaluation_corpora as $corpus){
foreach($evaluation_corpora as $corpus){
$yesterday_date = \Carbon\Carbon::now()->subDay()->format('Y-m-d');
StatsParser::updateStats('game', $corpus, $yesterday_date);
StatsParser::computeStats($corpus, $yesterday_date);
}
}
}
87 changes: 87 additions & 0 deletions app/Console/Commands/CreateLanguage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
// use Illuminate\Events\Dispatcher;
// use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use App\Models\Language;
use Artisan;

class CreateLanguage extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'language:create {language} {original_language=en}';

/** @var \Illuminate\Foundation\Application */
protected $app;
/** @var \Illuminate\Filesystem\Filesystem */
protected $files;

/**
* The console command description.
*
* @var string
*/
protected $description = 'Add a new language to the application';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Application $app, Filesystem $files)
{
$this->app = $app;
$this->files = $files;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

$new_language = $this->argument('language');
$original_language = $this->argument('original_language');


$new_directory = $this->app['path.lang']. DIRECTORY_SEPARATOR . $new_language;
$original_directory = $this->app['path.lang']. DIRECTORY_SEPARATOR . $original_language;

if(!$this->files->exists($original_directory)){
$this->error($original_language.' does not exist!');
return;
}

if($this->files->exists($new_directory)){
$this->error($new_language.' already exists!');
while(!in_array($overwrite = $this->askOverwriteExistingFiles(),['y','n'])){

}
if($overwrite=='n')
return;
}

$language = Language::firstOrCreate(['slug'=> $new_language]);
$this->files->copyDirectory($original_directory,$new_directory);
$this->files->copyDirectory(resource_path('views/lang/'.$original_language),resource_path('views/lang/'.$new_language));
Artisan::call('translations:import');

}

private function askOverwriteExistingFiles(){
return $this->ask('Overwrite the existing files (y/n)?');
}

}
53 changes: 46 additions & 7 deletions app/Console/Commands/ExportCorpus.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use App\Models\User;
use App\Models\Corpus;
use App\Models\Annotation;
use App\Models\Source;
use Gwaps4nlp\Models\Source;
use App\Models\ExportedCorpus;
use App\Services\ConllExporter;
use App\Services\MweExporter;

Expand Down Expand Up @@ -43,15 +44,53 @@ public function __construct()
*/
public function handle()
{
Annotation::computeScore();
// Annotation::computeScore();
$user = User::where('username','admin')->first();
$source_preannotated = Source::getPreAnnotated();
$corpora = Corpus::where('source_id','=',$source_preannotated->id)->get();
$corpora = Corpus::where('exportable',1)->get();

foreach($corpora as $corpus){
$parser = new ConllExporter($corpus,$user);
$file = str_replace(' ','-',$corpus->name).'-'.date('Ymd').'.conll';
$parser -> export($file);
if($corpus->id!=12)
continue;
if(count($corpus->subcorpora)){
$nb_sentences = 0;
$files = [];
$readme = $corpus->description."\xA";
$readme .= "This archive contains the files :\xA";
foreach($corpus->subcorpora as $subcorpus){
print("sub : ".$subcorpus->id. "\xA");
$parser = new ConllExporter($subcorpus,$user);
$file = str_replace(' ','-',$subcorpus->name).'-'.date('Ymd').'.conll';
$parser -> export($file);
if($parser->sentences_done>0){
$files[] = storage_path('export/'.$file);
$nb_sentences += $parser->sentences_done;
$readme.=$file."\xA";
if($subcorpus->url_source)
$readme.="Source : ".$subcorpus->url_source."\xA";
$readme.="License : ".$subcorpus->license->label."\xA\xA";
}
}

$file = str_replace(' ','-',$corpus->name).'-'.date('Ymd').'.zip';

$zipper = new \Chumper\Zipper\Zipper;

$zipper->make(storage_path('export/'.$file))
->folder($file)
->add($files)
->addString("README.txt", $readme);

$exported_corpus = ExportedCorpus::create(['file'=>$file,'user_id'=>$user->id,'corpus_id'=>$corpus->id]);
$exported_corpus->type = 'simple';
$exported_corpus->nb_sentences = $nb_sentences;
$exported_corpus->save();
}
else {
$parser = new ConllExporter($corpus,$user);
$file = str_replace(' ','-',$corpus->name).'-'.date('Ymd').'.conll';
$parser -> export($file);
}

}
$parser = new MweExporter($user);
$file = 'mwe-'.date('Ymd').'.csv';
Expand Down
50 changes: 50 additions & 0 deletions app/Console/Commands/ExportDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ExportDatabase extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:export';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Make a dump of the database and send it to a remote server';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$dump_file = storage_path('app/dump.sql');

$command = "mysqldump -h ".env('DB_HOST')." -u ".env('DB_USERNAME')." -p".env('DB_PASSWORD')." --databases ".env('DB_DATABASE')." > ".$dump_file;

system($command, $return_var);

$command_send_file = "scp ".$dump_file." ".config('database.backup-server.user')."@".config('database.backup-server.host').":".config('database.backup-server.path');
system($command_send_file, $return_var);

}
}
51 changes: 51 additions & 0 deletions app/Console/Commands/ImportDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ImportDatabase extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:import';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Imports the database backup.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if ($this->confirm('The current database will be overwritten. Are you sure you want to continue ?')) {

$dump_file = storage_path('app/dump.sql');

$command = "mysql -h ".env('DB_HOST')." -u ".env('DB_USERNAME')." -p".env('DB_PASSWORD')." ".env('DB_DATABASE')." < ".$dump_file;

system($command, $return_var);

}

}
}
Loading

0 comments on commit f98cba2

Please sign in to comment.