<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
 * This file is part of MODX Revolution.
 *
 * Copyright (c) MODX, LLC. All Rights Reserved.
 *
 * For complete copyright and license information, see the COPYRIGHT and LICENSE
 * files found in the top-level directory of this distribution.
 */
 -->
<!-- The following xPDO model represents an object-relational map structure of the MODX db registry package -->
<model package="MODX\Revolution\Sources" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="MODX\Revolution\Sources" version="3.0">

    <object class="modAccessMediaSource" table="access_media_source" extends="MODX\Revolution\modAccess">
        <field key="context_key" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="fk" />

        <index alias="context_key" name="context_key" primary="false" unique="false" type="BTREE">
            <column key="context_key" length="" collation="A" null="false" />
        </index>

        <aggregate alias="Target" class="MODX\Revolution\Sources\modMediaSource" local="target" foreign="id" owner="foreign" cardinality="one" />
        <aggregate alias="Context" class="MODX\Revolution\modContext" local="context_key" foreign="key" cardinality="one" owner="foreign" />
    </object>

    <object class="modMediaSource" table="media_sources" extends="MODX\Revolution\modAccessibleSimpleObject">
        <field key="name" dbtype="varchar" precision="191" phptype="string" null="false" default="" index="index"/>
        <field key="description" dbtype="text" phptype="string" null="true" />
        <field key="class_key" dbtype="varchar" precision="100" phptype="string" null="false" default="MODX\Revolution\Sources\modFileMediaSource" index="index" />
        <field key="properties" dbtype="mediumtext" phptype="array" null="true" />
        <field key="is_stream" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="1" index="index" />

        <index alias="name" name="name" primary="false" unique="false" type="BTREE">
            <column key="name" length="" collation="A" null="false" />
        </index>
        <index alias="class_key" name="class_key" primary="false" unique="false" type="BTREE">
            <column key="class_key" length="" collation="A" null="false" />
        </index>
        <index alias="is_stream" name="is_stream" primary="false" unique="false" type="BTREE">
            <column key="is_stream" length="" collation="A" null="false" />
        </index>

        <composite alias="SourceElement" class="MODX\Revolution\Sources\modMediaSourceElement" local="id" foreign="source" cardinality="one" owner="local" />
        <aggregate alias="Chunks" class="MODX\Revolution\modChunk" local="id" foreign="source" cardinality="many" owner="local" />
        <aggregate alias="Plugins" class="MODX\Revolution\modPlugin" local="id" foreign="source" cardinality="many" owner="local" />
        <aggregate alias="Snippets" class="MODX\Revolution\modSnippet" local="id" foreign="source" cardinality="many" owner="local" />
        <aggregate alias="Templates" class="MODX\Revolution\modTemplate" local="id" foreign="source" cardinality="many" owner="local" />
        <aggregate alias="TemplateVars" class="MODX\Revolution\modTemplateVar" local="id" foreign="source" cardinality="many" owner="local" />
    </object>
    <object class="modFileMediaSource" extends="MODX\Revolution\Sources\modMediaSource" />
    <object class="modS3MediaSource" extends="MODX\Revolution\Sources\modMediaSource" />
    <object class="modFTPMediaSource" extends="MODX\Revolution\Sources\modMediaSource" />

    <object class="modMediaSourceContext" table="media_sources_contexts" extends="xPDO\Om\xPDOObject">
        <field key="source" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="pk" />
        <field key="context_key" dbtype="varchar" precision="100" phptype="string" null="false" default="web" index="pk" />

        <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
            <column key="source" length="" collation="A" null="false" />
            <column key="context_key" length="" collation="A" null="false" />
        </index>

        <aggregate alias="Source" class="MODX\Revolution\Sources\modMediaSource" local="source" foreign="id" cardinality="one" owner="foreign" />
        <aggregate alias="Context" class="MODX\Revolution\modContext" local="context_key" foreign="key" cardinality="one" owner="foreign" />
    </object>

    <object class="modMediaSourceElement" table="media_sources_elements" extends="xPDO\Om\xPDOObject">
        <field key="source" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" />
        <field key="object_class" dbtype="varchar" precision="100" phptype="string" null="false" default="MODX\Revolution\modTemplateVar" index="pk" />
        <field key="object" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" />
        <field key="context_key" dbtype="varchar" precision="100" phptype="string" null="false" default="web" index="pk" />

        <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
            <column key="source" length="" collation="A" null="false" />
            <column key="object" length="" collation="A" null="false" />
            <column key="object_class" length="" collation="A" null="false" />
            <column key="context_key" length="" collation="A" null="false" />
        </index>

        <aggregate alias="Source" class="MODX\Revolution\Sources\modMediaSource" local="source" foreign="id" cardinality="one" owner="foreign" />
        <aggregate alias="Element" class="MODX\Revolution\modElement" local="object" foreign="id" cardinality="one" owner="foreign" />
        <aggregate alias="Context" class="MODX\Revolution\modContext" local="context_key" foreign="key" cardinality="one" owner="foreign" />
    </object>
</model>
