Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
8f65dc18
Commit
8f65dc18
authored
Aug 28, 2019
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid checking for plugin updates in each page refresh
parent
7ed3f6a0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
6 deletions
+58
-6
qa-admin.js
qa-content/qa-admin.js
+7
-0
PluginManager.php
qa-include/Q2A/Plugin/PluginManager.php
+25
-0
qa-lang-admin.php
qa-include/lang/qa-lang-admin.php
+1
-0
admin-plugins.php
qa-include/pages/admin/admin-plugins.php
+25
-6
No files found.
qa-content/qa-admin.js
View file @
8f65dc18
...
...
@@ -148,6 +148,13 @@ function qa_version_check(uri, version, elem, isCore)
);
}
function
qa_version_check_array
(
versionChecks
)
{
for
(
var
i
=
0
;
i
<
versionChecks
.
length
;
i
++
)
{
qa_version_check
(
versionChecks
[
i
].
uri
,
versionChecks
[
i
].
version
,
versionChecks
[
i
].
elem
,
false
)
}
}
function
qa_get_enabled_plugins_hashes
()
{
var
hashes
=
[];
...
...
qa-include/Q2A/Plugin/PluginManager.php
View file @
8f65dc18
...
...
@@ -25,6 +25,8 @@ class Q2A_Plugin_PluginManager
{
const
PLUGIN_DELIMITER
=
';'
;
const
OPT_ENABLED_PLUGINS
=
'enabled_plugins'
;
const
OPT_LAST_UPDATE_CHECK
=
'last_plugin_update_check'
;
const
NUMBER_OF_DAYS_TO_CHECK_FOR_UPDATE
=
14
;
private
$loadBeforeDbInit
=
array
();
private
$loadAfterDbInit
=
array
();
...
...
@@ -180,4 +182,27 @@ class Q2A_Plugin_PluginManager
$this
->
setEnabledPluginsOption
(
$finalEnabledPlugins
);
}
/**
* @return bool
*/
public
function
shouldCheckForUpdate
()
{
$lastUpdateCheck
=
(
int
)
qa_opt
(
self
::
OPT_LAST_UPDATE_CHECK
);
$currentTime
=
(
int
)
qa_opt
(
'db_time'
);
return
$currentTime
-
$lastUpdateCheck
>
self
::
NUMBER_OF_DAYS_TO_CHECK_FOR_UPDATE
*
24
*
60
*
60
;
}
/**
* @param int|null $time
*/
public
function
performUpdateCheck
(
$time
=
null
)
{
if
(
$time
===
null
)
{
$time
=
time
();
}
qa_opt
(
self
::
OPT_LAST_UPDATE_CHECK
,
$time
);
}
}
qa-include/lang/qa-lang-admin.php
View file @
8f65dc18
...
...
@@ -273,6 +273,7 @@ return array(
'users_registered'
=>
'Registered users:'
,
'users_title'
=>
'Users'
,
'users_voted'
=>
'Users who voted:'
,
'version_check'
=>
'Check for updates'
,
'version_get_x'
=>
'get ^'
,
'version_latest'
=>
'latest'
,
'version_latest_unknown'
=>
'latest unknown'
,
...
...
qa-include/pages/admin/admin-plugins.php
View file @
8f65dc18
...
...
@@ -62,7 +62,9 @@ if (qa_is_http_post()) {
$enabledPluginHashesArray
=
explode
(
';'
,
$enabledPluginHashes
);
$pluginDirectories
=
array_keys
(
array_intersect
(
$pluginHashes
,
$enabledPluginHashesArray
));
$pluginManager
->
setEnabledPlugins
(
$pluginDirectories
);
qa_redirect
(
'admin/plugins'
);
}
else
if
(
qa_clicked
(
'doversioncheck'
))
{
$pluginManager
->
performUpdateCheck
(
0
);
qa_redirect
(
'admin/plugins'
);
}
}
...
...
@@ -138,6 +140,9 @@ if (!empty($fileSystemPlugins)) {
qa_sort_by
(
$sortedPluginFiles
,
'name'
);
$versionChecks
=
array
();
$shouldCheckForUpdate
=
$pluginManager
->
shouldCheckForUpdate
();
$pluginIndex
=
-
1
;
foreach
(
$sortedPluginFiles
as
$pluginDirectory
=>
$metadata
)
{
$pluginIndex
++
;
...
...
@@ -168,14 +173,16 @@ if (!empty($fileSystemPlugins)) {
}
else
$authorhtml
=
''
;
if
(
$metaver
&&
isset
(
$metadata
[
'update_uri'
])
&&
strlen
(
$metadata
[
'update_uri'
]))
{
if
(
$
shouldCheckForUpdate
&&
$
metaver
&&
isset
(
$metadata
[
'update_uri'
])
&&
strlen
(
$metadata
[
'update_uri'
]))
{
$elementid
=
'version_check_'
.
md5
(
$pluginDirectory
);
$
updatehtml
=
'(<span id="'
.
$elementid
.
'">...</span>)'
;
$qa_content
[
'script_onloads'
][]
=
array
(
"qa_version_check("
.
qa_js
(
$metadata
[
'update_uri'
])
.
", "
.
qa_js
(
$metadata
[
'version'
],
true
)
.
", "
.
qa_js
(
$elementid
)
.
", false);"
$
versionChecks
[]
=
array
(
'uri'
=>
$metadata
[
'update_uri'
],
'version'
=>
$metadata
[
'version'
],
'elem'
=>
$elementid
,
);
$updatehtml
=
'(<span id="'
.
$elementid
.
'">...</span>)'
;
}
else
$updatehtml
=
''
;
...
...
@@ -246,6 +253,14 @@ if (!empty($fileSystemPlugins)) {
}
}
}
if
(
$shouldCheckForUpdate
)
{
$pluginManager
->
performUpdateCheck
();
$qa_content
[
'script_onloads'
][]
=
array
(
sprintf
(
'qa_version_check_array(%s);'
,
json_encode
(
$versionChecks
)),
);
}
}
$qa_content
[
'navigation'
][
'sub'
]
=
qa_admin_sub_navigation
();
...
...
@@ -260,6 +275,10 @@ $qa_content['form'] = array(
'tags'
=>
'name="dosave"'
,
'label'
=>
qa_lang_html
(
'admin/save_options_button'
),
),
'doversioncheck'
=>
array
(
'tags'
=>
'name="doversioncheck"'
,
'label'
=>
qa_lang_html
(
'admin/version_check'
),
),
),
'hidden'
=>
array
(
...
...
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