3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright Tech To The People http:tttp.eu (c) 2008 |
7 +--------------------------------------------------------------------+
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License along with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
28 require_once ('bin/cli.php');
29 require_once 'CRM/Core/BAO/Tag.php';
34 class tagsImporter
extends civicrm_cli
{
38 function __construct() {
39 parent
::__construct();
40 if (sizeof($this->args
) != 1) {
41 die("you need to profide a csv file (1st column parent name, 2nd tag name");
43 $this->file
= $this->args
[0];
44 $this->tags
= array_flip(CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)));
47 //format expected: parent name, tag
50 $handle = fopen($this->file
, "r");
52 // $header = fgetcsv($handle, 1000, ",");
53 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
56 $params = $this->convertLine($data);
57 $this->addTag($params);
68 function addTag($param) {
69 if (array_key_exists($param['name'], $this->tags
)) {
70 echo "\n- exists already: " . $param['name'];
73 $key = array('tag' => '');
74 if ($param['parent']) {
75 if (array_key_exists($param['parent'], $this->tags
)) {
76 $param['parent_id'] = $this->tags
[$param['parent']];
78 else $param['parent_id'] = $this->addTag(array(parent
=> '', name
=> $param['parent']));
79 $tag = CRM_Core_BAO_Tag
::add($param, $key);
80 echo "\n" . $tag->id
. ": create " . $param['name'] . " below " . $param['parent'];
83 $tag = CRM_Core_BAO_Tag
::add($param, $key);
84 echo "\n" . $tag->id
. ": create " . $param['name'] . " (root)";
86 $this->tags
[$param['name']] = $tag->id
;
90 /* return a params as expected */
96 function convertLine($data) {
98 [0] => parent tag name
99 [1] => name of the tag
103 $params['parent'] = $data[0];
104 $params['name'] = $data[1];
109 $tagsImporter = new tagsImporter("civicrm_value_1_extra_information");
110 $tagsImporter->run();