Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework print module #394

Open
wants to merge 24 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
676ac18
refactor
machiato32 Jan 3, 2024
d330b8b
remove printer role
machiato32 Jan 3, 2024
056fb9e
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
e038e09
Merge remote-tracking branch 'origin/development' into print-module-r…
machiato32 Jan 3, 2024
3689f71
remove printer role
machiato32 Jan 3, 2024
74b27a2
Merge branch 'print-module-refactor' of github.com:EotvosCollegium/ma…
machiato32 Jan 3, 2024
9d74515
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
1f3dbfb
solving todos
machiato32 Jan 3, 2024
c8f89bd
replace exec with process->run
machiato32 Jan 3, 2024
781ac18
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
913a4a6
added missing doc strings
machiato32 Jan 3, 2024
6612ad8
Merge branch 'print-module-refactor' of github.com:EotvosCollegium/ma…
machiato32 Jan 3, 2024
7ea9be0
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
1930767
add missing doc comments
machiato32 Jan 3, 2024
26c746f
Merge branch 'print-module-refactor' of github.com:EotvosCollegium/ma…
machiato32 Jan 3, 2024
ead482c
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
31527fe
fix
machiato32 Jan 3, 2024
e6547cb
Merge branch 'print-module-refactor' of github.com:EotvosCollegium/ma…
machiato32 Jan 3, 2024
62252a9
add missing doc comment
machiato32 Jan 3, 2024
d8fe598
style: format code with PHP CS Fixer
deepsource-autofix[bot] Jan 3, 2024
80db86f
fixes and #344
machiato32 Jan 3, 2024
e669bc1
Merge branch 'print-module-refactor' of github.com:EotvosCollegium/ma…
machiato32 Jan 3, 2024
d6fbe58
Created Process class, created PrinterHelper class, code improvements…
machiato32 May 9, 2024
1b1685c
style: format code with PHP CS Fixer
deepsource-autofix[bot] May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ PREVENT_ACCESSING_MISSING_ATTRIBUTES=false
PRINT_COST_ONESIDED=8
PRINT_COST_TWOSIDED=12
PRINTER_NAME=NemUjBela
PRINTER_IP=
PRINTER_PORT=

NETREG=1000
KKT=2000
Expand Down
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want these files in git?

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"julia.environmentPath": "c:\\Users\\sszajbely\\mars"
}
63 changes: 7 additions & 56 deletions app/Console/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console;

use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Process;

/**
* Collection of exec commands.
Expand All @@ -15,65 +16,15 @@ private static function isDebugMode()
return config('app.debug');
}

public static function getCompletedPrintingJobs()
{
$command = "lpstat -W completed -o " . config('print.printer_name') . " | awk '{print $1}'";
if (self::isDebugMode()) {
$result = [0];
} else {
$result = [];
exec($command, $result);
}
Log::info([$command, $result]);
return $result;
}

public static function print($command)
{
if (self::isDebugMode()) {
$job_id = 0;
$result = "request id is " . config('print.printer_name') . "-" . $job_id . " (1 file(s))";
} else {
$result = exec($command);
}
Log::info([$command, $result]);
return $result;
}

public static function cancelPrintJob(string $jobID)
{
$command = "cancel " . $jobID;
if (self::isDebugMode()) {
// cancel(1) exits with status code 0 if it succeeds
$result = ['output' => '', 'exit_code' => 0];
} else {
$output = exec($command, $result, $exit_code);
$result = ['output' => $output, 'exit_code' => $exit_code];
}
Log::info([$command, $result]);
return $result;
}

public static function getPages($path)
{
$command = "pdfinfo " . $path . " | grep '^Pages' | awk '{print $2}' 2>&1";
if (self::isDebugMode()) {
$result = rand(1, 10);
} else {
$result = exec($command);
}
Log::info([$command, $result]);
return $result;
}

public static function pingRouter($router)
{
if (self::isDebugMode()) {
$result = rand(1, 10) > 9 ? "error" : '';
} else {
// This happens too often to log.
$command = "ping " . $router->ip . " -c 1 | grep 'error\|unreachable'";
$result = exec($command);
$process = new Process(['ping', $router->ip, '-c', '1', '|', 'grep', "'error\|unreachable'"]);
$process->run();
$result = $process->getOutput();
}
return $result;
}
Expand All @@ -83,9 +34,9 @@ public static function latexToPdf($path, $outputDir)
if (self::isDebugMode()) {
$result = "ok";
} else {
$command = "pdflatex " . "-interaction=nonstopmode -output-dir " . $outputDir . " " . $path . " 2>&1";
Log::info($command);
$result = exec($command);
$process = new Process(['pdflatex', '-interaction=nonstopmode', '-output-dir', $outputDir, $path]);
$process->run();
$result = $process->getOutput();
}
return $result;
}
Expand Down
10 changes: 10 additions & 0 deletions app/Enums/PrintJobStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum PrintJobStatus: string {
case QUEUED = 'QUEUED';
case ERROR = 'ERROR';
case CANCELLED = 'CANCELLED';
case SUCCESS = 'SUCCESS';
}
2 changes: 0 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public function create(array $data)
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);

$user->roles()->attach(Role::firstWhere('name', Role::PRINTER)->id);
$user->roles()->attach(Role::firstWhere('name', $data['user_type'])->id);

if ($data['user_type'] == Role::TENANT) {
Expand Down
Loading
Loading