为vtiger创建模块

问题描述 投票:0回答:1

我想创建一个模块并在 vtiger 中开发它,所以我创建了一个包含一些脚本的文件。我在某处找到了这个并使用了它。据说它可以工作并制作表格,运行后如果再次运行脚本,则会出现此错误

Module already present - choose a different name
。我的问题是没有与新模块相关的文件夹,并且工具子菜单中也没有模块!如果我想更新它,例如添加任何字段或更改某些内容。怎么办?

这是我位于 vtiger 根目录中的文件:

<?php
include_once 'vtlib/Vtiger/Module.php';

$Vtiger_Utils_Log = true;

$MODULENAME = 'namava';

$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
    echo "Module already present - choose a different name.";
} else {
    $moduleInstance = new Vtiger_Module();
    $moduleInstance->name = $MODULENAME;
    $moduleInstance->parent = 'Tools';
    $moduleInstance->save();

    // Schema Setup
    $moduleInstance->initTables();

    // Field Setup
    $block = new Vtiger_Block();
    $block->label = 'LBL_' . strtoupper($moduleInstance->name) . '_INFORMATION';
    $moduleInstance->addBlock($block);

    $blockcf = new Vtiger_Block();
    $blockcf->label = 'LBL_CUSTOM_INFORMATION';
    $moduleInstance->addBlock($blockcf);

    $field1 = new Vtiger_Field();
    $field1->name = 'summary';
    $field1->label = 'Summary';
    $field1->uitype = 2;
    $field1->column = $field1->name;
    $field1->columntype = 'VARCHAR(255)';
    $field1->typeofdata = 'V~M';
    $block->addField($field1);

    $moduleInstance->setEntityIdentifier($field1);

    $field2 = new Vtiger_Field();
    $field2->name = 'film';
    $field2->label = 'film On';
    $field2->uitype = 5;
    $field2->column = $field2->name;
    $field2->columntype = 'Date';
    $field2->typeofdata = 'D~O';
    $block->addField($field2);

    $field3 = new Vtiger_Field();
    $field3->name = 'actor';
    $field3->label = 'actor on';
    $field3->uitype = 71;
    $field3->column = $field3->name;
    $field3->columntype = 'VARCHAR(255)';
    $field3->typeofdata = 'V~M';
    $block->addField($field3);

    $field3 = new Vtiger_Field();
    $field3->name = 'description';
    $field3->label = 'Description';
    $field3->uitype = 19;
    $field3->column = 'description';
    $field3->table = 'vtiger_crmentity';
    $blockcf->addField($field3);

    // Recommended common fields every Entity module should have (linked to core table)
    $mfield1 = new Vtiger_Field();
    $mfield1->name = 'assigned_user_id';
    $mfield1->label = 'Assigned To';
    $mfield1->table = 'vtiger_crmentity';
    $mfield1->column = 'smownerid';
    $mfield1->uitype = 53;
    $mfield1->typeofdata = 'V~M';
    $block->addField($mfield1);

    $mfield2 = new Vtiger_Field();
    $mfield2->name = 'CreatedTime';
    $mfield2->label = 'Created Time';
    $mfield2->table = 'vtiger_crmentity';
    $mfield2->column = 'createdtime';
    $mfield2->uitype = 70;
    $mfield2->typeofdata = 'T~O';
    $mfield2->displaytype = 2;
    $block->addField($mfield2);

    $mfield3 = new Vtiger_Field();
    $mfield3->name = 'ModifiedTime';
    $mfield3->label = 'Modified Time';
    $mfield3->table = 'vtiger_crmentity';
    $mfield3->column = 'modifiedtime';
    $mfield3->uitype = 70;
    $mfield3->typeofdata = 'T~O';
    $mfield3->displaytype = 2;
    $block->addField($mfield3);

    // Filter Setup
    $filter1 = new Vtiger_Filter();
    $filter1->name = 'All';
    $filter1->isdefault = true;
    $moduleInstance->addFilter($filter1);
    $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);

    // Sharing Access Setup
    $moduleInstance->setDefaultSharing();
}

我还使用了另一种方法来创建模块的骨架

php vtlib/tools/console.php
但我的问题是它只创建一个字段,我不知道如何用这种方式在代码中添加更多字段

你能告诉我如何以标准方式做到这一点吗?

php vtiger vtigercrm
1个回答
0
投票
  1. 错误:模块已存在 - 选择不同的名称

这意味着您已经执行了脚本或者您正在尝试使用现有模块名称创建模块。查看脚本文件中的 if 条件。

  1. 添加新字段

如果您仍然希望添加更多字段,那么您需要删除该 if 条件以及此代码块。

// Add a New module, and remove these 4 lines once the script is executed and the module exists in the vtiger_tab table.

$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent = 'Tools';
$moduleInstance->save();

// This line creates new tables for your module
// 1. vtiger_modulename
// 2. vtiger_modulenamecf

$moduleInstance->initTables();

// This code block adds a new Block and adds an entry in vtiger_blocks. If it does not exist then you can re-execute else remove it from a script.

$block = new Vtiger_Block();
$block->label = 'LBL_' . strtoupper($moduleInstance->name) . '_INFORMATION';
$moduleInstance->addBlock($block);
  1. 在菜单中添加模块

在脚本中添加此行以在菜单中添加模块名称

Settings_MenuEditor_Module_Model::addModuleToApp($moduleInstance->name, $moduleInstance->parent);
© www.soinside.com 2019 - 2024. All rights reserved.