1: <?php
2: /**
3: * Updates the content listings of a package.xml file.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Pear
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Pear
12: */
13:
14: /**
15: * Updates the content listings of a package.xml file.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Pear
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Pear
27: */
28: class Horde_Pear_Package_Task_UpdateContents
29: implements Horde_Pear_Package_Task
30: {
31: /**
32: * The package.xml handler.
33: *
34: * @var Horde_Pear_Package_Xml
35: */
36: private $_xml;
37:
38: /**
39: * The contents handler.
40: *
41: * @var Horde_Pear_Package_Contents
42: */
43: private $_content;
44:
45: /**
46: * Additional options.
47: *
48: * @var array
49: */
50: private $_options;
51:
52: /**
53: * Constructor.
54: *
55: * @param Horde_Pear_Package_Xml $xml The package.xml file to
56: * operate on.
57: * @param Horde_Pear_Package_Contents $content The content list.
58: * @param array $options Additional options.
59: */
60: public function __construct(Horde_Pear_Package_Xml $xml,
61: Horde_Pear_Package_Contents $content = null,
62: $options = array())
63: {
64: $this->_xml = $xml;
65: $this->_options = $options;
66: if ($content === null) {
67: $this->_content = $this->_xml->getContent();
68: } else {
69: $this->_content = $content;
70: }
71: }
72:
73: /**
74: * Execute the task.
75: *
76: * @return NULL
77: */
78: public function run()
79: {
80: $contents = $this->_xml->findNode('/p:package/p:contents/p:dir');
81: if ($contents && !empty($this->_options['regenerate'])) {
82: $contents = $this->_xml->findNode('/p:package/p:contents');
83: $this->_xml->removeWhitespace($contents->previousSibling);
84: $this->_xml->findNode('/p:package')->removeChild($contents);
85: $contents = false;
86: }
87:
88: $filelist = $this->_xml->findNode('/p:package/p:phprelease/p:filelist');
89: if ($filelist && !empty($this->_options['regenerate'])) {
90: $filelist = $this->_xml->findNode('/p:package/p:phprelease');
91: $this->_xml->removeWhitespace($filelist->previousSibling);
92: $this->_xml->findNode('/p:package')->removeChild($filelist);
93: $filelist = false;
94: }
95:
96: if (!$contents) {
97: $root = $this->_xml->insert(
98: array(
99: 'contents' => array(),
100: "\n ",
101: ),
102: $this->_xml->findNode('/p:package/p:dependencies')
103: );
104: $contents = $this->_xml->append(
105: array(
106: "\n ",
107: 'dir' => array('baseinstalldir' => '/', 'name' => '/'),
108: ' ',
109: $this->_xml->createComment(' / '),
110: "\n ",
111: ),
112: $root
113: );
114: $this->_xml->append("\n ", $contents);
115: }
116:
117: if (!$filelist) {
118: $root = $this->_xml->insert(
119: array(
120: 'phprelease' => array(),
121: "\n ",
122: ),
123: $this->_xml->findNode('/p:package/p:changelog')
124: );
125:
126: $filelist = $this->_xml->append(
127: array(
128: "\n ",
129: 'filelist' => array(),
130: "\n ",
131: ),
132: $root
133: );
134: $this->_xml->append("\n ", $filelist);
135: }
136:
137: $current = $this->_xml->createContents($this->_xml, $contents, $filelist);
138: $current->update($this->_content);
139: try {
140: if (empty($this->_options['no_timestamp'])) {
141: $this->_xml->timestamp();
142: }
143: $this->_xml->syncCurrentVersion();
144: } catch (Horde_Pear_Exception $e) {
145: /**
146: * Ignore errors in this operation as it is not mandatory for
147: * updating the file list.
148: */
149: }
150: }
151:
152: }