Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
don
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
25
Issues
25
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
Operations
Operations
Incidents
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
LQDN Adminsys
don
Commits
d5206315
Commit
d5206315
authored
Oct 13, 2018
by
Guinness
Committed by
okhin
Oct 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix piplomes
parent
f67edd27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
16 deletions
+17
-16
app/controller/cron.php
app/controller/cron.php
+17
-16
No files found.
app/controller/cron.php
View file @
d5206315
...
...
@@ -41,7 +41,7 @@ class Cron extends Controller
// We do have our IDs
// We need to create a PDF
$lock
=
@
fopen
(
"tmp/piplomes.lock"
,
"ab"
);
$lock
=
@
fopen
(
"
../
tmp/piplomes.lock"
,
"ab"
);
if
(
$lock
)
{
flock
(
$lock
,
LOCK_EX
);
foreach
(
$pdfs
as
$pdf
)
{
...
...
@@ -64,7 +64,7 @@ class Cron extends Controller
// Let's trash the garbage
foreach
(
array
(
'tex'
,
'aux'
,
'pdf'
,
'log'
)
as
$ext
)
{
@
unlink
(
dirname
(
__FILE__
)
.
"/../tmp/pplome."
.
$ext
);
@
unlink
(
dirname
(
__FILE__
)
.
"/../
../
tmp/pplome."
.
$ext
);
}
// We now have only fr or en templates
...
...
@@ -76,10 +76,10 @@ class Cron extends Controller
}
$logger
->
write
(
"Language is "
.
$pdf
[
'lang'
]
.
""
);
$template
=
file_get_contents
(
dirname
(
__FILE__
)
.
"/../locales/"
.
$pdf
[
'lang'
]
.
"/LC_MESSAGES/plome.tex"
);
$template
=
file_get_contents
(
dirname
(
__FILE__
)
.
"/../
../
locales/"
.
$pdf
[
'lang'
]
.
"/LC_MESSAGES/plome.tex"
);
// We will open the pi-decimals file
$pi
=
fopen
(
dirname
(
__FILE__
)
.
"/../static/pi-billion.txt"
,
"rb"
);
$pi
=
fopen
(
dirname
(
__FILE__
)
.
"/../
../www/
static/pi-billion.txt"
,
"rb"
);
if
(
!
$pi
)
{
$logger
->
write
(
"FATAL: Can't open decimals"
);
exit
();
...
...
@@ -100,7 +100,7 @@ class Cron extends Controller
// Let's replace the templates with values
file_put_contents
(
dirname
(
__FILE__
)
.
"/../tmp/pplome.tex"
,
dirname
(
__FILE__
)
.
"/../
../
tmp/pplome.tex"
,
str_replace
(
"%%DECIMALES%%"
,
$decimales
,
...
...
@@ -118,13 +118,13 @@ class Cron extends Controller
// Let's create the pdf from the template
$logger
->
write
(
"Building the pdf from the tex template"
);
$command
=
'TEXINPUTS='
.
dirname
(
__FILE__
)
.
'/tex/:$TEXINPUTS '
;
$command
=
'TEXINPUTS='
.
dirname
(
__FILE__
)
.
'/
../../
tex/:$TEXINPUTS '
;
// We need to set an env variable first
putenv
(
'TEXINPUTS='
.
dirname
(
__FILE__
)
.
'/../tex:'
.
getenv
(
'TEXINPUTS'
));
putenv
(
'TEXINPUTS='
.
dirname
(
__FILE__
)
.
'/../
../
tex:'
.
getenv
(
'TEXINPUTS'
));
$command
.
=
'/usr/bin/pdflatex '
;
$command
.
=
'-output-directory='
.
dirname
(
__FILE__
)
.
"/../tmp "
;
$command
.
=
dirname
(
__FILE__
)
.
"/../tmp/pplome.tex"
;
$command
.
=
'-output-directory='
.
dirname
(
__FILE__
)
.
"/../
../
tmp "
;
$command
.
=
dirname
(
__FILE__
)
.
"/../
../
tmp/pplome.tex"
;
$logger
->
write
(
$command
);
exec
(
$command
,
$output
,
$return
);
foreach
(
$output
as
$line
)
{
...
...
@@ -141,11 +141,11 @@ class Cron extends Controller
// Move the pdf to its position
@
unlink
(
PIPLOME_PATH
.
$pdf
[
'hash'
]
.
".pdf"
);
$logger
->
write
(
"Moving pdf to "
.
PIPLOME_PATH
.
$pdf
[
'hash'
]
.
".pdf"
);
@
rename
(
dirname
(
__FILE__
)
.
"/../tmp/pplome.pdf"
,
PIPLOME_PATH
.
$pdf
[
'hash'
]
.
".pdf"
);
@
rename
(
dirname
(
__FILE__
)
.
"/../
../
tmp/pplome.pdf"
,
PIPLOME_PATH
.
$pdf
[
'hash'
]
.
".pdf"
);
// Let's trash the garbage
foreach
(
array
(
'tex'
,
'aux'
,
'pdf'
,
'log'
)
as
$ext
)
{
@
unlink
(
dirname
(
__FILE__
)
.
"/../tmp/pplome."
.
$ext
);
@
unlink
(
dirname
(
__FILE__
)
.
"/../
../
tmp/pplome."
.
$ext
);
}
// Saving the pathin database
...
...
@@ -167,17 +167,18 @@ class Cron extends Controller
$result
=
$db
->
query
(
"SELECT dons.id as id,
decimale,
users.pseudo as nom,
lang
lang,
pdf
FROM dons
LEFT JOIN users ON dons.user_id = users.id
WHERE dons.status IN (1, 4, 101)
AND dons.id='"
.
\
Utils
::
asl
(
$args
[
'id'
])
.
"'"
);
$pdf
=
$result
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
$fp
=
fopen
(
PIPLOME_PATH
.
$pdf
[
'
hash
'
]
.
".pdf"
,
"rb"
);
$fp
=
fopen
(
PIPLOME_PATH
.
$pdf
[
'
pdf
'
]
.
".pdf"
,
"rb"
);
if
(
$fp
)
{
$fsize
=
filesize
(
PIPLOME_PATH
.
$pdf
[
'
hash
'
]
.
".pdf"
);
$fsize
=
filesize
(
PIPLOME_PATH
.
$pdf
[
'
pdf
'
]
.
".pdf"
);
header
(
"Content-Type: application/pdf"
);
header
(
"Content-Disposition: attachment; filename=
\"
"
.
$pdf
[
'
hash
'
]
.
".pdf
\"
"
);
header
(
"Content-Disposition: attachment; filename=
\"
"
.
$pdf
[
'
pdf
'
]
.
".pdf
\"
"
);
header
(
"Content-Length:
$fsize
"
);
while
(
!
feof
(
$fp
))
{
$buffer
=
fread
(
$fp
,
2048
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment