[Hook] - add new/better hooks about apps' lifecycle - events: enable / disable / update / migrate
I must feed a database table on install and / or to check its content when updating (migrate).
Could a hook feature do the trick or is there something else?
For updating you could write an app that provides a "appinfo/update.php". For the install part I'm not sure. Even if a hook is provided, your app will not be enabled at that time.
@PVince81 : thanks a lot for the "appinfo/update.php" - works fine. @MTRichards : I don't understand what is expected here ( need more information ) ?
Need more information was set because it is no clear what kind of issue you are having. Also we usually expect people to use the issue template here https://raw.github.com/owncloud/core/master/issue_template.md when raising an issue.
I guess in your case the problem is already solved ?
Hi @pf18387 What @PVince81 said, in that we couldn't figure out what the issue was or what we needed to do.
Problem: How an app could feed / check a Database table on install / update (migrate) events?
A) Kind of issue: enhancement ( on install, according to PVince81 ):question:
B) Kind of issue: bug (on update) Steps to reproduce:
- write an app "appinfo/update.php"
- increase the app version number
- use owncloud (any function / feature / app)
Expected behaviour: "appinfo/update.php" is executed.
Actual behaviour: The entire latest migration process is executed:-1: - the "appinfo/update.php" is also executed :+1:
Server configuration OS: Linux debian 3.2.0-4-486 #1 Debian 3.2.60-1+deb7u3 i686 Web server: Apache 2.0 Database: MySQL 5.5.38-0+wheezy1 PHP version: 5.4.4-14+deb7u14 ownCloud version: 7.0.2.1 Updated from an older ownCloud or fresh install: updated from 7.0.1 or updated from 7.0.2 List of activated apps: SELECT * FROM oc_appconfig WHERE configkey = 'enabled' AND configvalue = 'yes'
admin_migrate, calendar, contacts, files%, firstrunwizard, gallery, media, mozilla_sync, oc_apps2_games, oc_apps2_geoloc, search_lucene, updater, user_migrate
The content of config/config.php:
<?php
$CONFIG = array (
'instanceid' => '52985786c5d7b',
'passwordsalt' => '***',
'datadirectory' => '/var/www/owncloud/data',
'dbtype' => 'mysql',
'version' => '7.0.2.1',
'dbname' => 'owncloud',
'dbhost' => 'localhost',
'dbtableprefix' => 'oc_',
'dbuser' => '***',
'dbpassword' => '***',
'installed' => true,
'loglevel' => '0',
'theme' => '',
'maintenance' => false,
'mail_domain' => '***',
'session_lifetime' => 86400,
'session_keepalive' => true,
'custom_csp_policy' => 'default-src \'self\'; script-src \'self\' \'unsafe-eval\'; style-src \'self\' \'unsafe-inline\'; frame-src *; img-src *; font-src \'self\' data:; media-src *',
'trusted_domains' =>
array (
0 => '***',
1 => '***',
2 => '***',
),
'check_for_working_htaccess' => false,
);
Are you using external storage, if yes which one: No Are you using encryption: No
Client configuration Browser: FF32.0.1, IE11.0.12, Chrome 37.0.2062.120 m Operating system: WinXP, Win7
Owncloud log: {"reqId":"5416e0db0aba6","app":"core","message":"starting upgrade from 7.0.2.1 to 7.0.2.1","level":0,"time":"2014-09-15T12:51:39+00:00","method":"GET","url":"/oc/core/ajax/update.php?requesttoken=5ae25669ce7bbd550cf4"} {"reqId":"5416e0db0aba6","app":"games","message":"(I70) update started.","level":0,"time":"2014-09-15T12:51:43+00:00","method":"GET","url":"/oc/core/ajax/update.php?requesttoken=5ae25669ce7bbd550cf4"} {"reqId":"5416e0db0aba6","app":"games","message":"(I70) update terminated successfully.","level":0,"time":"2014-09-15T12:51:43
@PVince81 @MTRichards Thanks for your replies ; I hope this report sounds better.
From your last comment it seems that you'd like to prevent the whole migration to be run when only one app needs an update, is that correct ? Is that you're asking for ?
Sorry, just re-read my old comment, so basically the request is to provide a hook that makes it possible for an app to execute code when enabled.
I understood it initially as "whenever ownCloud is installed, run code" but maybe you wanted to say "run code whenever an app is enabled"
This makes it the following feature request:
- Provide a hook for apps to be able to execute code when activated / deactivate
- Provide a hook for apps to be able to execute code when updated (currently possible with
appinfo/update.php.
I think this makes sense, some apps might want to initialize themselves when they get enabled, not when the user first accesses.
I understood it initially as "whenever ownCloud is installed, run code" but maybe you wanted to say "run code whenever an app is enabled"
That's right: whenever an app is enabled.
- Provide a hook for apps to be able to execute code when activated / deactivated
Deactivated is even better than expected!
- Provide a hook for apps to be able to execute code when updated (currently possible with
appinfo/update.php)
I agree with you, this is possible but, in my opinion, it should be improved. For the moment
- whenever an user (anyone) will click then an upgrade could be executed (weird)
- the "owncloud.log" shows that the upgrade has taken 4 seconds to do some unnecessary upgrade
I think this makes sense, some apps might want to initialize themselves when they get enabled, not when the user first accesses.
when an app get enabled/disabled or updated (app version number increased) or upgraded (ownCloud version number increased)
@pf18387 is seems there is already a postEnable hook, found this in the encryption app, see:
https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/helper.php#L82
@PVince81 Thanks. I've looked at the postEnable hook - but it looks like a typo post_disable -> postEnable
\OCP\Util::connectHook('OC_App', 'post_disable', 'OCA\Encryption\Hooks', 'postEnable
');
We could fix a bug there :pensive: - but does it mean there is a post_enable hook we could use?
https://github.com/owncloud/core/blob/master/lib/private/app.php#L1114
In my humble opinion, there are at least three issues (side effects) and one enhancement, now:
- https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/helper.php#L82 where a
post_disablehook calls apostEnablefunction - "appinfo/update.php" that executes an entire migration process instead of executing only the "appinfo/update.php"
- According to the log, "starting upgrade from 7.0.2.1 to 7.0.2.1" is feasible and takes 4 seconds to execute (it should not even execute, and should not waste as much time to do nothing)
- Enhancement: provide the following hooks (thanks to @PVince81 :+1: who helped rewriting the request) :
- pre_upgrade, post_upgrade,
- pre_update, post_update,
- pre_enable, post_enable,
- pre_disable, post_disable
Last, @MTRichards the Milestone "need more information" - really? :smirk:
This request should be split into separate tickets.
I suggest at least moving 2/3 into a bug ticket: the core update routine should not be run when core version did not change. As you say it can waste some time.
- is probably not an issue but might be intended, at least in the way how the encryption app uses it. (@schiesbn please double check)
We can keep this ticket here for 4 to add new/better hooks.
@PVince81 Can you create those tickets? Thanks
Starting with 9.1 we have repair steps which can be defined in info.xml to be executed either before the database migration, after the migration or after the whole upgrade mechanism being executed in a background job.
This should fit the needs of this ticket.
I came to the same requirement (need to execute code on app enable). Is there a place where this workaround using info.xml is documented? Can't find it at a first glance in the docs
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.