Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Feeds
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Feeds
Commits
91c9a735
Commit
91c9a735
authored
3 years ago
by
Andrew Dolgov
Browse files
Options
Downloads
Patches
Plain Diff
deal with phpstan warnings in plugins/cache_starred_images.php
parent
931a7533
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/cache_starred_images/init.php
+17
-14
17 additions, 14 deletions
plugins/cache_starred_images/init.php
with
17 additions
and
14 deletions
plugins/cache_starred_images/init.php
+
17
−
14
View file @
91c9a735
<?php
<?php
class
Cache_Starred_Images
extends
Plugin
{
class
Cache_Starred_Images
extends
Plugin
{
/* @var PluginHost $host */
/*
*
@var PluginHost $host */
private
$host
;
private
$host
;
/* @var DiskCache $cache */
/** @var DiskCache $cache */
private
$cache
;
private
$cache
;
private
$max_cache_attempts
=
5
;
// per-article
/** @var int $max_cache_attempts (per article) */
private
$max_cache_attempts
=
5
;
function
about
()
{
function
about
()
{
return
array
(
null
,
return
array
(
null
,
...
@@ -32,8 +35,8 @@ class Cache_Starred_Images extends Plugin {
...
@@ -32,8 +35,8 @@ class Cache_Starred_Images extends Plugin {
}
}
}
}
/** since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */
function
hook_house_keeping
()
{
function
hook_house_keeping
()
{
/* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */
Debug
::
log
(
"caching media of starred articles for user "
.
$this
->
host
->
get_owner_uid
()
.
"..."
);
Debug
::
log
(
"caching media of starred articles for user "
.
$this
->
host
->
get_owner_uid
()
.
"..."
);
...
@@ -53,7 +56,7 @@ class Cache_Starred_Images extends Plugin {
...
@@ -53,7 +56,7 @@ class Cache_Starred_Images extends Plugin {
$usth
=
$this
->
pdo
->
prepare
(
"UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"
);
$usth
=
$this
->
pdo
->
prepare
(
"UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"
);
while
(
$line
=
$sth
->
fetch
())
{
while
(
$line
=
$sth
->
fetch
())
{
Debug
::
log
(
"processing article "
.
$line
[
"title"
],
Debug
::
$
LOG_VERBOSE
);
Debug
::
log
(
"processing article "
.
$line
[
"title"
],
Debug
::
LOG_VERBOSE
);
if
(
$line
[
"site_url"
])
{
if
(
$line
[
"site_url"
])
{
$success
=
$this
->
cache_article_images
(
$line
[
"content"
],
$line
[
"site_url"
],
$line
[
"owner_uid"
],
$line
[
"id"
]);
$success
=
$this
->
cache_article_images
(
$line
[
"content"
],
$line
[
"site_url"
],
$line
[
"owner_uid"
],
$line
[
"id"
]);
...
@@ -115,7 +118,7 @@ class Cache_Starred_Images extends Plugin {
...
@@ -115,7 +118,7 @@ class Cache_Starred_Images extends Plugin {
foreach
(
$entries
as
$entry
)
{
foreach
(
$entries
as
$entry
)
{
if
(
$entry
->
hasAttribute
(
'src'
))
{
if
(
$entry
->
hasAttribute
(
'src'
))
{
$src
=
rewrite_relative
_url
(
$site_url
,
$entry
->
getAttribute
(
'src'
));
$src
=
UrlHelper
::
rewrite_relative
(
$site_url
,
$entry
->
getAttribute
(
'src'
));
$local_filename
=
$article_id
.
"-"
.
sha1
(
$src
);
$local_filename
=
$article_id
.
"-"
.
sha1
(
$src
);
...
@@ -130,11 +133,11 @@ class Cache_Starred_Images extends Plugin {
...
@@ -130,11 +133,11 @@ class Cache_Starred_Images extends Plugin {
return
$doc
;
return
$doc
;
}
}
private
function
cache_url
(
$article_id
,
$url
)
{
private
function
cache_url
(
int
$article_id
,
string
$url
)
:
bool
{
$local_filename
=
$article_id
.
"-"
.
sha1
(
$url
);
$local_filename
=
$article_id
.
"-"
.
sha1
(
$url
);
if
(
!
$this
->
cache
->
exists
(
$local_filename
))
{
if
(
!
$this
->
cache
->
exists
(
$local_filename
))
{
Debug
::
log
(
"cache_images: downloading:
$url
to
$local_filename
"
,
Debug
::
$
LOG_VERBOSE
);
Debug
::
log
(
"cache_images: downloading:
$url
to
$local_filename
"
,
Debug
::
LOG_VERBOSE
);
$data
=
UrlHelper
::
fetch
([
"url"
=>
$url
,
"max_size"
=>
Config
::
get
(
Config
::
MAX_CACHE_FILE_SIZE
)]);
$data
=
UrlHelper
::
fetch
([
"url"
=>
$url
,
"max_size"
=>
Config
::
get
(
Config
::
MAX_CACHE_FILE_SIZE
)]);
...
@@ -150,16 +153,16 @@ class Cache_Starred_Images extends Plugin {
...
@@ -150,16 +153,16 @@ class Cache_Starred_Images extends Plugin {
return
false
;
return
false
;
}
}
private
function
cache_article_images
(
$content
,
$site_url
,
$owner_uid
,
$article_id
)
{
private
function
cache_article_images
(
string
$content
,
string
$site_url
,
int
$owner_uid
,
int
$article_id
)
:
bool
{
$status_filename
=
$article_id
.
"-"
.
sha1
(
$site_url
)
.
".status"
;
$status_filename
=
$article_id
.
"-"
.
sha1
(
$site_url
)
.
".status"
;
/* housekeeping might run as a separate user, in this case status/media might not be writable */
/* housekeeping might run as a separate user, in this case status/media might not be writable */
if
(
!
$this
->
cache
->
is_writable
(
$status_filename
))
{
if
(
!
$this
->
cache
->
is_writable
(
$status_filename
))
{
Debug
::
log
(
"status not writable:
$status_filename
"
,
Debug
::
$
LOG_VERBOSE
);
Debug
::
log
(
"status not writable:
$status_filename
"
,
Debug
::
LOG_VERBOSE
);
return
false
;
return
false
;
}
}
Debug
::
log
(
"status:
$status_filename
"
,
Debug
::
$
LOG_VERBOSE
);
Debug
::
log
(
"status:
$status_filename
"
,
Debug
::
LOG_VERBOSE
);
if
(
$this
->
cache
->
exists
(
$status_filename
))
if
(
$this
->
cache
->
exists
(
$status_filename
))
$status
=
json_decode
(
$this
->
cache
->
get
(
$status_filename
),
true
);
$status
=
json_decode
(
$this
->
cache
->
get
(
$status_filename
),
true
);
...
@@ -170,7 +173,7 @@ class Cache_Starred_Images extends Plugin {
...
@@ -170,7 +173,7 @@ class Cache_Starred_Images extends Plugin {
// only allow several download attempts for article
// only allow several download attempts for article
if
(
$status
[
"attempt"
]
>
$this
->
max_cache_attempts
)
{
if
(
$status
[
"attempt"
]
>
$this
->
max_cache_attempts
)
{
Debug
::
log
(
"too many attempts for
$site_url
"
,
Debug
::
$
LOG_VERBOSE
);
Debug
::
log
(
"too many attempts for
$site_url
"
,
Debug
::
LOG_VERBOSE
);
return
false
;
return
false
;
}
}
...
@@ -194,7 +197,7 @@ class Cache_Starred_Images extends Plugin {
...
@@ -194,7 +197,7 @@ class Cache_Starred_Images extends Plugin {
$has_images
=
true
;
$has_images
=
true
;
$src
=
rewrite_relative
_url
(
$site_url
,
$entry
->
getAttribute
(
'src'
));
$src
=
UrlHelper
::
rewrite_relative
(
$site_url
,
$entry
->
getAttribute
(
'src'
));
if
(
$this
->
cache_url
(
$article_id
,
$src
))
{
if
(
$this
->
cache_url
(
$article_id
,
$src
))
{
$success
=
true
;
$success
=
true
;
...
@@ -210,7 +213,7 @@ class Cache_Starred_Images extends Plugin {
...
@@ -210,7 +213,7 @@ class Cache_Starred_Images extends Plugin {
while
(
$enc
=
$esth
->
fetch
())
{
while
(
$enc
=
$esth
->
fetch
())
{
$has_images
=
true
;
$has_images
=
true
;
$url
=
rewrite_relative
_url
(
$site_url
,
$enc
[
"content_url"
]);
$url
=
UrlHelper
::
rewrite_relative
(
$site_url
,
$enc
[
"content_url"
]);
if
(
$this
->
cache_url
(
$article_id
,
$url
))
{
if
(
$this
->
cache_url
(
$article_id
,
$url
))
{
$success
=
true
;
$success
=
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment