@@ 92-115 (lines=24) @@ | ||
89 | * |
|
90 | * @return Result |
|
91 | */ |
|
92 | public function publish(string $productName, string $source = '', Command &$callingCommand = null): Result |
|
93 | { |
|
94 | $result = new Result(); |
|
95 | $commonName = strtolower($productName); |
|
96 | $productDirectory = sprintf('%s/%s', $this->workingDirectory, $commonName); |
|
97 | ||
98 | $this->setExecutionStartTime(); |
|
99 | if (!$this->readyResourceDirectory($productDirectory)) { |
|
100 | return $result->setError(sprintf('Product directory %s is not writable.', $productDirectory)) |
|
101 | ->setData((object)['executionTime' => $this->getExecutionTime()]); |
|
102 | } |
|
103 | ||
104 | $product = $this->productFactory->create($productDirectory); |
|
105 | $result = $this->productPublisher->publish($product, $source); |
|
106 | ||
107 | foreach ($result->getMessages() as $message) { |
|
108 | $this->tell($message); |
|
109 | } |
|
110 | ||
111 | $data = $result->getData() ?? (object)[]; |
|
112 | $data->executionTime = $this->getExecutionTime(); |
|
113 | ||
114 | return $result->setData($data); |
|
115 | } |
|
116 | ||
117 | /** |
|
118 | * @param string $productName |
|
@@ 125-149 (lines=25) @@ | ||
122 | * |
|
123 | * @return Result |
|
124 | */ |
|
125 | public function update(string $productName, Command &$callingCommand = null): Result |
|
126 | { |
|
127 | $this->callingCommand = $callingCommand; |
|
128 | $result = new Result(); |
|
129 | $commonName = strtolower($productName); |
|
130 | $productDirectory = sprintf('%s/%s', $this->workingDirectory, $commonName); |
|
131 | ||
132 | $this->setExecutionStartTime(); |
|
133 | if (!$this->readyResourceDirectory($productDirectory)) { |
|
134 | return $result->setError(sprintf('Product directory %s is not writable.', $productDirectory)) |
|
135 | ->setData((object)['executionTime' => $this->getExecutionTime()]); |
|
136 | } |
|
137 | ||
138 | $product = $this->productFactory->create($productDirectory); |
|
139 | $result = $this->productPublisher->update($product); |
|
140 | ||
141 | foreach ($result->getMessages() as $message) { |
|
142 | $this->tell($message); |
|
143 | } |
|
144 | ||
145 | $data = $result->getData() ?? (object)[]; |
|
146 | $data->executionTime = $this->getExecutionTime(); |
|
147 | ||
148 | return $result->setData($data); |
|
149 | } |
|
150 | ||
151 | /** |
|
152 | * @param null|Command $callingCommand |