【问题标题】:PyroCMS module creation is failing while working with Streams使用 Streams 时 PyroCMS 模块创建失败
【发布时间】:2014-12-28 16:58:00
【问题描述】:

我在PyroCMS 2.2.5 模块中工作,这就是我在details.php 文件中所做的:

public function install() {
    $this->dbforge->drop_table( 'payment' );

    $this->load->driver( 'Streams' );

    $this->streams->utilities->remove_namespace( 'payment' );
    if ( $this->db->table_exists( 'data_streams' ) ) {
        $this->db->where( 'stream_namespace', 'payment' )->delete( 'data_streams' );
    }

    $this->install_tables( array(
        'payment' => array(
            'id'            => array(
                'type'           => 'INT',
                'constraint'     => 11,
                'auto_increment' => true,
                'primary'        => true
            ),
            'transactionID' => array(
                'type'       => 'VARCHAR',
                'constraint' => 128
            ),
            'orderTime'     => array(
                'type' => 'TIMESTAMP',
                'null' => false
            ),
            'toReload'      => array(
                'type'       => 'DECIMAL',
                'null'       => false,
                'constraint' => array( 9, 6 ),
                'unsigned'   => false
            ),
            'amt'           => array(
                'type'       => 'DECIMAL',
                'null'       => false,
                'constraint' => array( 9, 6 ),
                'unsigned'   => false
            ),
            'feeAmt'        => array(
                'type'       => 'DECIMAL',
                'null'       => false,
                'constraint' => array( 9, 6 ),
                'unsigned'   => false
            ),
            'currencyCode'  => array(
                'type'       => 'VARCHAR',
                'constraint' => 25
            ),
            'paymentStatus' => array(
                'type'       => 'VARCHAR',
                'constraint' => 25
            ),
            'pendingReason' => array(
                'type' => 'TEXT'
            )
        )
    ) );

    $this->streams->streams->add_stream(
        'lang:payment:streams:payment:name',
        'payment',
        'payment',
        null,
        null
    );

    $this->streams->fields->add_fields( array(
        array(
            'name'         => 'lang:payment:fields:transactionID',
            'slug'         => 'transactionID',
            'namespace'    => 'payment',
            'type'         => 'text',
            'assign'       => 'payment',
            'title_column' => true,
            'required'     => true
        ),
        array(
            'name'         => 'lang:payment:fields:orderTime',
            'slug'         => 'orderTime',
            'namespace'    => 'payment',
            'type'         => 'datetime',
            'extra'        => array( 'storage' => 'unix' ),
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => false,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:toReload',
            'slug'         => 'toReload',
            'namespace'    => 'payment',
            'type'         => 'decimal',
            'extra'        => array( 'decimal_places' => 2 ),
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => true,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:amt',
            'slug'         => 'amt',
            'namespace'    => 'payment',
            'type'         => 'decimal',
            'extra'        => array( 'decimal_places' => 2 ),
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => true,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:feeAmt',
            'slug'         => 'feeAmt',
            'namespace'    => 'payment',
            'type'         => 'decimal',
            'extra'        => array( 'decimal_places' => 2 ),
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => true,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:currencyCode',
            'slug'         => 'currencyCode',
            'namespace'    => 'payment',
            'type'         => 'text',
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => true,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:paymentStatus',
            'slug'         => 'paymentStatus',
            'namespace'    => 'payment',
            'type'         => 'text',
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => true,
            'unique'       => false
        ),
        array(
            'name'         => 'lang:payment:fields:pendingReason',
            'slug'         => 'pendingReason',
            'namespace'    => 'payment',
            'type'         => 'text',
            'assign'       => 'payment',
            'title_column' => false,
            'required'     => false,
            'unique'       => false
        )
    ) );

    $this->db->insert_batch( 'settings',
        array(
            array(
                'slug'        => 'pay-sbx',
                'title'       => 'Activar modo Sandbox?',
                'description' => 'Establece si se usara el modo sbx para pruebas',
                'type'        => 'select',
                'value'       => 1,
                'options'     => '0=No|1=Sí',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => 1,
                'module'      => 'payment',
                'order'       => 829
            ),
            array(
                'slug'        => 'paypalFee',
                'title'       => 'Fee PayPal',
                'description' => 'Fee de PayPal',
                'type'        => 'text',
                'value'       => '',
                'options'     => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => 1,
                'module'      => 'payment',
                'order'       => 828
            ),
            array(
                'slug'        => 'paypalDiscount',
                'title'       => 'Descuento PayPal',
                'description' => 'Descuento de PayPal',
                'type'        => 'text',
                'value'       => '',
                'options'     => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => 1,
                'module'      => 'payment',
                'order'       => 827
            ),
            array(
                'slug'        => 'pay-application-id-sbx',
                'title'       => 'PayPal Sandbox App ID (*)',
                'description' => 'PayPal Application ID (The application is only required with Adaptive Payments applications. You obtain your application ID but submitting it for approval within your developer account at http://developer.paypal.com. We are using shorthand if/else statements here to set both Sandbox and Production values. Your sbx values go on the left and your live values go on the right. The sbx value included here is a global value provided for developrs to use in the PayPal sbx.)',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 826
            ),
            array(
                'slug'        => 'pay-application-id-live',
                'title'       => 'PayPal Live App ID',
                'description' => 'PayPal Application ID (The application is only required with Adaptive Payments applications. You obtain your application ID but submitting it for approval within your developer account at http://developer.paypal.com. We are using shorthand if/else statements here to set both Sandbox and Production values. Your sbx values go on the left and your live values go on the right. The sbx value included here is a global value provided for developrs to use in the PayPal sbx.)',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 815
            ),
            array(
                'slug'        => 'pay-developer-account',
                'title'       => 'PayPal Developer Account Email Address (*)',
                'description' => 'This is the email address that you use to sign in to http://developer.paypal.com',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 825
            ),
            array(
                'slug'        => 'pay-api_username-sbx',
                'title'       => 'PayPal Username API Credentials (Sandbox) (*)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 824
            ),
            array(
                'slug'        => 'pay-api_username-live',
                'title'       => 'PayPal Username API Credentials (Live)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 814
            ),
            array(
                'slug'        => 'pay-api_password-sbx',
                'title'       => 'PayPal Password API Credentials (Sandbox) (*)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 823
            ),
            array(
                'slug'        => 'pay-api_password-live',
                'title'       => 'PayPal Password API Credentials (Live)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 813
            ),
            array(
                'slug'        => 'pay-api_signature-sbx',
                'title'       => 'PayPal Signature API Credentials (Sandbox) (*)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 822
            ),
            array(
                'slug'        => 'pay-api_signature-live',
                'title'       => 'PayPal Signature API Credentials (Live)',
                'description' => 'These are your PayPal API credentials for working with the PayPal gateway directly. These are used any time you are using the parent PayPal class within the library. You may obtain these credentials by logging into the following with your PayPal account: https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 812
            ),
            array(
                'slug'        => 'pay-rest_client_id-sbx',
                'title'       => 'PayPal REST API Username Credentials (Sandbox) (*)',
                'description' => 'These are the API credentials used for the PayPal REST API. These are used any time you are working with the REST API child class.',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 819
            ),
            array(
                'slug'        => 'pay-rest_client_id-live',
                'title'       => 'PayPal REST API Username Credentials (Live)',
                'description' => 'These are the API credentials used for the PayPal REST API. These are used any time you are working with the REST API child class.',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 807
            ),
            array(
                'slug'        => 'pay-rest_client_secret-sbx',
                'title'       => 'PayPal REST API Secret Credentials (Sandbox) (*)',
                'description' => 'These are the API credentials used for the PayPal REST API. These are used any time you are working with the REST API child class.',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 1,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 818
            ),
            array(
                'slug'        => 'pay-rest_client_secret-live',
                'title'       => 'PayPal REST API Secret Credentials (Live)',
                'description' => 'These are the API credentials used for the PayPal REST API. These are used any time you are working with the REST API child class.',
                'type'        => 'text',
                'value'       => '',
                'is_required' => 0,
                'is_gui'      => 1,
                'default'     => '',
                'options'     => '',
                'module'      => 'payment',
                'order'       => 806
            )
        ) );

    return true;
}

public function uninstall() {
    $fieldsToDelete = array(
        'paypalFee',
        'paypalDiscount',
        'pay-sbx',
        'pay-application-id-sbx',
        'pay-application-id-live',
        'pay-developer-account',
        'pay-api_username-sbx',
        'pay-api_username-live',
        'pay-api_password-sbx',
        'pay-api_password-live',
        'pay-api_signature-sbx',
        'pay-api_signature-live',
        'pay-rest_client_id-sbx',
        'pay-rest_client_id-live',
        'pay-rest_client_secret-sbx',
        'pay-rest_client_secret-live'
    );

    $this->db->where_in( 'slug', $fieldsToDelete );
    $this->db->delete( 'settings' );

    $dataFields = array(
        'transactionID',
        'orderTime',
        'toReload',
        'amt',
        'feeAmt',
        'currencyCode',
        'paymentStatus',
        'pendingReason'
    );

    $this->db->where_in( 'field_slug', $dataFields );
    $this->db->delete( 'data_fields' );

    $this->load->driver( 'Streams' );
    $this->streams->utilities->remove_namespace( 'payment' );
    if ( $this->db->table_exists( 'data_streams' ) ) {
        $this->db->where( 'stream_namespace', 'payment' )->delete( 'data_streams' );
    }

    $this->dbforge->drop_table( 'payment' );

    return true;
}

模块,显然已安装和卸载,但我注意到这里缺少一些东西,这就是我正在运行的问题,如果我了解流的工作原理,那么

  • 安装模块后,data_streams 表上应该会出现一个新行,对吗?在我的情况下没有创建,为什么?我错过了什么?卸载模块时则相反,对吗?
  • 安装模块后,应该在data_field_assignments 中添加一些条目,对吗?就我而言,正如我之前所说的那样,这没有发生,再次,为什么?我错过了什么吗?

谁能给我一些帮助或建议?

PS:祝大家年终快乐

【问题讨论】:

    标签: php codeigniter codeigniter-2 pyrocms


    【解决方案1】:

    这是一个关于如何使用流创建模块的简单样板:

    假设一个名为my_module的模块

    public function install()
    {
        //Create your stream
        if ( ! $this->streams->streams->add_stream(lang('streams:name'), 'my_module', 'my_module', '', null))
        {
            //Something went wrong so uninstall
            $this->uninstall();
    
            return false;
        }
    
        //Now we have the streams so create the fields
        $fields = array(
            array(
                'name'         => lang('my_module:fields:name'),
                'slug'         => 'my_fields_slug',
                'namespace'    => 'my_module',
                'type'         => 'text',
                'extra'        => array('max_length' => 100),
                'instructions' => lang('my_module:fields:instr:name'),
                'assign'       => 'my_module',
                'title_column' => true,
                'required'     => true,
                'unique'       => true
            ),
            ....
            ....
        );
    
       // Add fields to the stream
       $this->streams->fields->add_fields($fields);
    
       return true;
    }
    
    public function uninstall()
    {
        //remove stream
        $this->streams->utilities->remove_namespace('my_module');
    
        //Drop table, strems do not do that
        $this->dbforge->drop_table('my_module');
    
        return true;
    }
    

    看看这个例子:https://github.com/pyrocms/streams-enabled-module-sample

    【讨论】:

      【解决方案2】:

      您有一些文档要阅读。

      不要创建流表。不要丢弃它,或者使用 Streams Utility 来销毁命名空间:http://docs.pyrocms.com/2.2/manual/developers/tools/streams-api/utilities-driver#remove_namespace(namespace_slug)。这也将拆除该命名空间中的字段和分配。正确拆除一切。

      仅使用流驱动程序来添加流:http://docs.pyrocms.com/2.2/manual/developers/tools/streams-api/streams-driver#add_stream。这将创建表并自动添加 data_streams 记录。但是如果表存在则返回 false,因为它假定 Stream 已经存在。

      当您添加字段时,您需要使用字段驱动程序将它们分配给流:http://docs.pyrocms.com/2.2/manual/developers/tools/streams-api/fields-driver#assign_field(namespace,stream_slug,field_slug,assign_data:array)。这将自动为字段创建列并运行分配挂钩。

      【讨论】:

        猜你喜欢
        • 2014-10-26
        • 2021-03-21
        • 2020-02-25
        • 1970-01-01
        • 1970-01-01
        • 2020-01-11
        • 2012-05-28
        • 2016-04-29
        • 2019-02-07
        相关资源
        最近更新 更多