Skip to content

Centralize configuration in appinfo/info.xml #1235

Closed

Description

@BernhardPosselt

The discussion was started in #1214

At the moment app developers have to configure their app settings in various different places . This includes: navigation entry settings, versions for schema updates, classloader and checks for enabled apps, etc

Sometimes you have to do this using PHP, sometimes its XML and sometimes its just a plain file with a number in it. This is inconsistent and takes more energy to document and understand. Also by using PHP for things that get loaded before all apps, the risk is high that one syntax error in one app can break every app.

We came up with the following additions to the info.xml file

<?xml version="1.0"?>
<app>
    <id>myapp</id>
    <name>My App</name>
    <description>My App description</description>
    <version>1.0</version>
    <licences>
        <licence>AGPL</licence>
    </licences>
    <authors>
        <author>
            <name>myname</name>
            <email>[email protected]</email>
        </author>
    </authors>

    <require>5.0</require>

    <admin linkType="route">myapp_index</admin>

    <search>
        <provider>\OCA\MyApp\SearchProvider</provider>
    </search>

    <share>
        <backend>\OCA\MyApp\ShareBackend</backend>
    </share>

    <backgroundjobs>
        <job runType="worker">\OCA\MyApp\BackgroundJob</job>
    </backgroundjobs>

    <dependencies>
        <app>appframework</app>
    </dependencies>
</app>

Heres my schema file which validates the xml:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!-- types -->
  <xs:simpleType name="notEmpty">
    <xs:restriction base="xs:string">
      <xs:minLength value="1"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="version">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]+(\.[0-9]+)*"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="email">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-\.]+\..+"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="loweralpha">
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z]+"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- actual xml -->
  <xs:element name="app">
    <xs:complexType>
      <xs:all>

        <xs:element name="id" type="loweralpha" />
        <xs:element name="name" type="notEmpty" />
        <xs:element name="description" type="notEmpty" />
        <xs:element name="version" type="version" />

        <!-- allow one or more licences -->
        <xs:element name="licences">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="licence" minOccurs="1" maxOccurs="unbounded" type="notEmpty" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- allow one or more authors -->
        <xs:element name="authors">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="author">
                <xs:complexType>
                  <xs:all>
                    <xs:element name="name" type="notEmpty" />
                    <xs:element name="email" type="email" />
                  </xs:all>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- minimum owncloud version -->
        <xs:element name="require" type="version" />

        <!-- if the app can be used as a webapp for instance by gnome web -->
        <xs:element name="webapp" type="xs:boolean" minOccurs="0" maxOccurs="1"/>

        <!-- if the app is in the installed tar, 3rdparty apps must set false -->
        <xs:element name="shipped" type="xs:boolean" minOccurs="0" maxOccurs="1"/>

        <!-- if the app should be enabled by default -->
        <xs:element name="default-enable" type="xs:boolean" minOccurs="0" maxOccurs="1"/>

        <!-- types can be given and be only of value: 
          * filesystem
          * prelogin 
          * authentication
          * logging
        -->
        <xs:element name="types" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="type" minOccurs="1" maxOccurs="unbounded">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="filesystem" />
                    <xs:enumeration value="prelogin" />
                    <xs:enumeration value="authentication" />
                    <xs:enumeration value="logging" />
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- contains the link to the admin settings page and can specify a
        link or a route -->
        <xs:element name="admin" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="notEmpty">
                <xs:attribute name="linkType" use="required">
                  <xs:simpleType>
                    <xs:restriction base="xs:string">
                      <xs:enumeration value="file" />
                      <xs:enumeration value="route" />
                    </xs:restriction>
                  </xs:simpleType>
                </xs:attribute>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>

        <!-- Can be specified and contains a list of search provider classes-->
        <xs:element name="search" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="provider" type="notEmpty" minOccurs="1" maxOccurs="unbounded"></xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- Can be specified and contains a list of share backend classes-->
        <xs:element name="share" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="backend" type="notEmpty" minOccurs="1" maxOccurs="unbounded"></xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- Allows to specify app dependencies -->
        <xs:element name="dependencies" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="app" type="notEmpty" minOccurs="1" maxOccurs="unbounded"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <!-- Allows to specify background jobs of type:
          * worker
          * regular
          * queue 
        -->
        <xs:element name="backgroundjobs" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="job" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="notEmpty">
                      <xs:attribute name="runType" use="required">
                        <xs:simpleType>
                          <xs:restriction base="xs:string">
                            <xs:enumeration value="regular" />
                            <xs:enumeration value="worker" />
                            <xs:enumeration value="queue" />
                          </xs:restriction>
                        </xs:simpleType>
                      </xs:attribute>
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

      </xs:all>
    </xs:complexType>
  </xs:element>


</xs:schema>

Activity

  1. tanghus commented on Jan 19, 2013

    @tanghus
    Contributor

    The appinfo/version files was originally introduced to speed up reading owncloud-archive/apps@121c5f4
    I don't know if this is still an issue /cc @icewind1991

  2. BernhardPosselt commented on Jan 19, 2013

    @BernhardPosselt
    ContributorAuthor

    sounds a lot like premature optimization. If this really is an issue (which i highly doubt) caching should solve the problem.

  3. DeepDiver1975 commented on Jan 19, 2013

    @DeepDiver1975
    Contributor

    What about routes?

    Please explain the two index and icon elements in navigation. 

    I'm not too sure about the elements reflecting the register calls/elements. Let me think about it.

    Thx

  4. BernhardPosselt commented on Jan 19, 2013

    @BernhardPosselt
    ContributorAuthor

    Im not sure if everyone wants to use routes. For those that still want the OC method linkTo

    <index type="file">index.php</index>
    

    can be used. The icon uses imagePath which takes two arguments: appname and filename.

    <icon app="core">icon.svg</icon>
    

    should be better in that case. Basically there will be only one element, this is just for demonstrating the choices

    Edit:
    As for routes: I've tried to put this into config files before but it lost a huge amount of configurability. Also the way how the routes.php is parsed (required inside the router class so you use $this) makes it REALLY hard to decouple, if not impossible.

  5. icewind1991 commented on Jan 19, 2013

    @icewind1991
    Contributor

    sounds a lot like premature optimization. If this really is an issue (which i highly doubt) caching should solve the problem.

    Before I split the version number to a separate file, reading all the xml files took nearly 50% of the page load time.
    Version number is the only thing that we can't cache from the config file since the version number is used to check if we need to update the cache.

    I agree with moving all the other things to the xml file (and cache them in the database)

  6. BernhardPosselt commented on Jan 19, 2013

    @BernhardPosselt
    ContributorAuthor
  7. icewind1991 commented on Jan 19, 2013

    @icewind1991
    Contributor

    That could be a solution, as long as we can guaranty that every change is detected

  8. BernhardPosselt commented on Jan 19, 2013

    @BernhardPosselt
    ContributorAuthor

    Oh sry, this should be guaranteed by using http://php.net/manual/en/function.filemtime.php :

    This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.

  9. bartv2 commented on Jan 19, 2013

    @bartv2
    Contributor

    stating files also takes time, but i'm not sure how it compares with reading version files. also dbversion could just be a int, no need to have that minor there, when it is only for database schema changes.

  10. BernhardPosselt commented on Jan 20, 2013

    @BernhardPosselt
    ContributorAuthor

    Well we cant say anything for sure without performance tests. Another solution would be to hash the content of file and compare it with a hash in the database, although I'm not sure how performant that will be.

  11. BernhardPosselt commented on Jan 20, 2013

    @BernhardPosselt
    ContributorAuthor

    Just tested filemtime vs file_get_contents with 10000 empty files:

    • file_get_contents: 0.080702066421509 sec
    • filemtime: 0.023054838180542 sec

    filemtime is roughly 3-4 times faster.

  12. karlitschek commented on Jan 20, 2013

    @karlitschek
    Contributor

    It's a common misunderstanding that databases are fast. Most of the time the local filesystem is significantly faster then a database so caching things in a database doesn't always make sense. So it would be great if you could do a brief check of the old and new codepath before merging this. I just commited a small trivial tool that I did years ago to compare the performance of an old and a new codepath. Perhaps this is helpful to you. https://github.com/owncloud/administration/blob/master/dev-tools/benchmark.php

  13. icewind1991 commented on Jan 20, 2013

    @icewind1991
    Contributor

    The main cost here isn't reading the file from the filesystem, but parsing the xml

  14. karlitschek commented on Jan 20, 2013

    @karlitschek
    Contributor

    @icewind1991 True. XML parsing is also famous for being slow. :-) would be great to have some performance numbers for both options.

  15. BernhardPosselt commented on Jan 20, 2013

    @BernhardPosselt
    ContributorAuthor

    What about serialized classes? If that is possible in PHP at all.

  16. BernhardPosselt commented on Mar 11, 2013

    @BernhardPosselt
    ContributorAuthor

    bump

  17. houqp commented on Mar 11, 2013

    @houqp
    Contributor

    If it's parsing xml that takes time, can we just search the <version>1.0</version> tag from the file and read the version number? I mean treat it as a normal palintext file instead of XML during page load.

  18. BernhardPosselt commented on Mar 11, 2013

    @BernhardPosselt
    ContributorAuthor

    @houqp caching is the answer ;)

  19. houqp commented on Mar 11, 2013

    @houqp
    Contributor

    cool, would like to see it adopted since it will be very helpful for app developers :)

  20. VicDeo commented on Jun 20, 2013

    @VicDeo
    Contributor

    @Raydiation it would be great to implement PHP extensions dependency check.

  21. BernhardPosselt commented on May 7, 2014

    @BernhardPosselt
    ContributorAuthor

    Closing this since I've given up on finding a solution in core. I have a working version of all the proposed stuff in news in JSON format, if someone is interested in that please open another issue and mention me.

  22. locked as resolved and limited conversation to collaborators on Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions