core icon indicating copy to clipboard operation
core copied to clipboard

[Hook] - add new/better hooks about apps' lifecycle - events: enable / disable / update / migrate

Open pf18387 opened this issue 12 years ago • 16 comments

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?

pf18387 avatar Sep 05 '14 08:09 pf18387

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 avatar Sep 05 '14 09:09 PVince81

@PVince81 : thanks a lot for the "appinfo/update.php" - works fine. @MTRichards : I don't understand what is expected here ( need more information ) ?

pf18387 avatar Sep 15 '14 09:09 pf18387

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 ?

PVince81 avatar Sep 15 '14 09:09 PVince81

Hi @pf18387 What @PVince81 said, in that we couldn't figure out what the issue was or what we needed to do.

MTRichards avatar Sep 15 '14 11:09 MTRichards

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:

  1. write an app "appinfo/update.php"
  2. increase the app version number
  3. 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.

pf18387 avatar Sep 15 '14 14:09 pf18387

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 ?

PVince81 avatar Sep 15 '14 14:09 PVince81

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:

  1. Provide a hook for apps to be able to execute code when activated / deactivate
  2. 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.

PVince81 avatar Sep 15 '14 14:09 PVince81

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.

  1. Provide a hook for apps to be able to execute code when activated / deactivated

Deactivated is even better than expected!

  1. 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

  1. whenever an user (anyone) will click then an upgrade could be executed (weird)
  2. 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 avatar Sep 15 '14 15:09 pf18387

@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 avatar Sep 19 '14 13:09 PVince81

@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

pf18387 avatar Sep 19 '14 16:09 pf18387

In my humble opinion, there are at least three issues (side effects) and one enhancement, now:

  1. https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/helper.php#L82 where a post_disable hook calls a postEnable function
  2. "appinfo/update.php" that executes an entire migration process instead of executing only the "appinfo/update.php"
  3. 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)
  4. 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:

pf18387 avatar Oct 01 '14 09:10 pf18387

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.

  1. 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 avatar Oct 06 '14 09:10 PVince81

@PVince81 Can you create those tickets? Thanks

MorrisJobke avatar Jan 09 '15 15:01 MorrisJobke

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.

DeepDiver1975 avatar Jun 14 '16 10:06 DeepDiver1975

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

bne86 avatar Oct 05 '16 12:10 bne86

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.

lock[bot] avatar Aug 03 '19 12:08 lock[bot]