|
11 | 11 | namespace Joomla\Component\Finder\Administrator\Model; |
12 | 12 |
|
13 | 13 | use Joomla\CMS\Factory; |
14 | | -use Joomla\CMS\Filter\OutputFilter; |
15 | 14 | use Joomla\CMS\Form\Form; |
16 | 15 | use Joomla\CMS\MVC\Model\AdminModel; |
17 | 16 | use Joomla\Component\Finder\Administrator\Table\FilterTable; |
18 | | -use Joomla\String\StringHelper; |
19 | 17 |
|
20 | 18 | // phpcs:disable PSR1.Files.SideEffects |
21 | 19 | \defined('_JEXEC') or die; |
@@ -153,137 +151,4 @@ public function getTotal() |
153 | 151 |
|
154 | 152 | return $db->setQuery($query)->loadResult(); |
155 | 153 | } |
156 | | - |
157 | | - /** |
158 | | - * Method to save the form data. |
159 | | - * |
160 | | - * Overrides the parent to correctly handle the 'save2copy' task for Finder filters. |
161 | | - * |
162 | | - * @param array $data The form data. |
163 | | - * |
164 | | - * @return boolean True on success, false on failure. |
165 | | - * |
166 | | - * @since 5.4.1 |
167 | | - */ |
168 | | - public function save($data) |
169 | | - { |
170 | | - $app = Factory::getApplication(); |
171 | | - $task = $app->getInput()->get('task', '', 'cmd'); |
172 | | - |
173 | | - if ($task === 'save2copy') { |
174 | | - $data['filter_id'] = 0; |
175 | | - |
176 | | - $title = trim((string) ($data['title'] ?? '')); |
177 | | - $alias = trim((string) ($data['alias'] ?? '')); |
178 | | - |
179 | | - if ($alias === '') { |
180 | | - $alias = OutputFilter::stringURLSafe($title); |
181 | | - } |
182 | | - |
183 | | - // Generate unique title + alias |
184 | | - list($title, $alias) = $this->generateNewTitleAndAlias($title, $alias); |
185 | | - |
186 | | - $data['title'] = $title; |
187 | | - $data['alias'] = $alias; |
188 | | - } |
189 | | - |
190 | | - return parent::save($data); |
191 | | - } |
192 | | - |
193 | | - /** |
194 | | - * Generate a new unique title and alias for a copied filter. |
195 | | - * Follows the same logic as Joomla's core content models. |
196 | | - * |
197 | | - * @param string $title The original title. |
198 | | - * @param string $alias The original alias. |
199 | | - * |
200 | | - * @return array Array with [newTitle, newAlias]. |
201 | | - * |
202 | | - * @since 5.4.1 |
203 | | - */ |
204 | | - protected function generateNewTitleAndAlias(string $title, string $alias): array |
205 | | - { |
206 | | - $db = $this->getDatabase(); |
207 | | - |
208 | | - if (preg_match('/^(.*?)(?:\s\((\d+)\))?$/', $title, $matches)) { |
209 | | - $baseTitle = trim($matches[1]); |
210 | | - } else { |
211 | | - $baseTitle = trim($title); |
212 | | - } |
213 | | - |
214 | | - $baseAlias = trim($alias ?: OutputFilter::stringURLSafe($title)); |
215 | | - |
216 | | - $likeTitle = $db->quote($db->escape($baseTitle, true) . '%', false); |
217 | | - |
218 | | - $query = $db->getQuery(true) |
219 | | - ->select($db->quoteName('title')) |
220 | | - ->from($db->quoteName('#__finder_filters')) |
221 | | - ->where($db->quoteName('title') . ' LIKE ' . $likeTitle); |
222 | | - |
223 | | - $existingTitles = $db->setQuery($query)->loadColumn(); |
224 | | - |
225 | | - $maxNum = 0; |
226 | | - foreach ($existingTitles as $existing) { |
227 | | - if (preg_match('/^\Q' . $baseTitle . '\E(?:\s\((\d+)\))?$/', $existing, $matches)) { |
228 | | - $num = isset($matches[1]) ? (int) $matches[1] : 1; |
229 | | - if ($num > $maxNum) { |
230 | | - $maxNum = $num; |
231 | | - } |
232 | | - } |
233 | | - } |
234 | | - |
235 | | - $nextNum = $maxNum + 1; |
236 | | - |
237 | | - $newTitle = $baseTitle; |
238 | | - if ($nextNum > 1) { |
239 | | - $newTitle .= ' (' . $nextNum . ')'; |
240 | | - } |
241 | | - |
242 | | - // Build a unique alias |
243 | | - $newAlias = $this->getUniqueAlias($baseAlias); |
244 | | - |
245 | | - return [$newTitle, $newAlias]; |
246 | | - } |
247 | | - |
248 | | - /** |
249 | | - * Ensure a unique alias in the table by incrementing with dash style. |
250 | | - * |
251 | | - * |
252 | | - * @param string $base The starting alias (already URL-safe). |
253 | | - * |
254 | | - * @return string A unique alias. |
255 | | - * |
256 | | - * @since 5.4.1 |
257 | | - */ |
258 | | - protected function getUniqueAlias(string $base): string |
259 | | - { |
260 | | - $alias = $base !== '' ? $base : OutputFilter::stringURLSafe(uniqid('filter-', true)); |
261 | | - |
262 | | - while ($this->aliasExists($alias)) { |
263 | | - $alias = StringHelper::increment($alias, 'dash'); |
264 | | - } |
265 | | - |
266 | | - return $alias; |
267 | | - } |
268 | | - |
269 | | - /** |
270 | | - * Check whether an alias exists in the table. |
271 | | - * |
272 | | - * @param string $alias The alias to test. |
273 | | - * |
274 | | - * @return boolean True if it exists, false otherwise. |
275 | | - * |
276 | | - * @since 5.4.1 |
277 | | - */ |
278 | | - protected function aliasExists(string $alias): bool |
279 | | - { |
280 | | - $db = $this->getDatabase(); |
281 | | - $query = $db->getQuery(true) |
282 | | - ->select('COUNT(*)') |
283 | | - ->from($db->quoteName('#__finder_filters')) |
284 | | - ->where($db->quoteName('alias') . ' = :alias') |
285 | | - ->bind(':alias', $alias); |
286 | | - |
287 | | - return (int) $db->setQuery($query)->loadResult() > 0; |
288 | | - } |
289 | 154 | } |
0 commit comments