Component::delete()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 15
cts 15
cp 1
rs 8.8571
cc 5
eloc 11
nc 5
nop 1
crap 5
1
<?php
2
3
namespace BootPress\Sitemap;
4
5
use BootPress\Page\Component as Page;
6
use BootPress\Asset\Component as Asset;
7
use BootPress\SQLite\Component as SQLite;
8
use BootPress\Hierarchy\Component as Hierarchy;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class Component
12
{
13
    /**
14
     * To access the Sitemap database
15
     * 
16
     * @var \BootPress\SQLite\Component
17
     */
18
    public $db;
19
    
20
    /**
21
     * @var int[]
22
     */
23
    private $ids;
24
    
25
    /**
26
     * @var mixed[]
27
     */
28
    private $stmt = array();
29
    
30
    /**
31
     * @var bool
32
     */
33
    private $transaction = false;
34
35
    /**
36
     * Opens the Sitemap database.
37
     */
38 14
    public function __construct()
39
    {
40 14
        $page = Page::html();
41 14
        $this->db = new SQLite($page->file('Sitemap.db'));
42 14
        if ($this->db->created) {
43 4
            $this->db->fts->create('search', array( // snippet order of preference
44 4
                'description',
45 4
                'content',
46 4
                'title',
47 4
                'path',
48 4
                'keywords',
49 4
            ), 'porter');
50 4
            $this->db->create('sitemap', array(
51 4
                'docid' => 'INTEGER PRIMARY KEY',
52 4
                'category_id' => 'INTEGER NOT NULL DEFAULT 0',
53 4
                'path' => 'TEXT UNIQUE COLLATE NOCASE',
54 4
                'thumb' => 'TEXT DEFAULT NULL',
55 4
                'info' => 'TEXT NOT NULL DEFAULT ""',
56 4
                'content' => 'TEXT NOT NULL DEFAULT ""',
57 4
                'hash' => 'TEXT NOT NULL DEFAULT ""',
58 4
                'updated' => 'INTEGER NOT NULL DEFAULT 0',
59 4
                'deleted' => 'INTEGER NOT NULL DEFAULT 0',
60 4
            ), 'category_id');
0 ignored issues
show
Documentation introduced by
'category_id' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61 4
            $this->db->create('categories', array(
62 4
                'id' => 'INTEGER PRIMARY KEY',
63 4
                'category' => 'TEXT UNIQUE COLLATE NOCASE',
64 5
                'parent' => 'INTEGER NOT NULL DEFAULT 0',
65 4
                'level' => 'INTEGER NOT NULL DEFAULT 0',
66 4
                'lft' => 'INTEGER NOT NULL DEFAULT 0',
67 4
                'rgt' => 'INTEGER NOT NULL DEFAULT 0',
68 4
            ));
69 4
        }
70 14
    }
71
72
    /**
73
     * Wraps up the database, and closes the connection.  Always unset() the sitemap when you are done using it, especially when you ``$this->reset()``, ``$this->upsert()``, and ``$this->delete()`` anything.
74
     */
75 14
    public function __destruct()
76
    {
77 14
        foreach ($this->stmt as $action => $tables) {
78 6
            foreach ($tables as $stmt) {
79 6
                $this->db->close($stmt);
80 6
            }
81 14
        }
82 14
        if (isset($this->stmt['insert']['categories'])) {
83 4
            $hier = new Hierarchy($this->db, 'categories');
84 4
            $hier->refresh('category');
85 4
        }
86 14
        if ($this->transaction) {
87 6
            $this->db->exec('COMMIT');
88 6
        }
89 14
        $this->db->connection()->close();
90 14
    }
91
92
    /**
93
     * Generates the sitemap[...].xml files to display, and removes 404 pages as they come to our attention.
94
     * 
95
     * @param int $limit   The number of links to display per page.
96
     * @param int $expires The number of seconds you would like to cache the response.
97
     * 
98
     * @return \Symfony\Component\HttpFoundation\Response|false
99
     */
100 2
    public static function page($limit = 10000, $expires = 0)
101
    {
102 2
        $page = Page::html();
103 2
        if (preg_match('/^sitemap(\-(?P<category>[a-z-]+)(\-(?P<num>[0-9]+))?)?\.xml$/i', $page->url['path'], $xml)) {
104 2
            $last_modified = 0;
105 2
            if (!empty($xml['category'])) {
106 2
                $category = strtolower($xml['category']);
107 2
                $num = (isset($xml['num'])) ? (int) $xml['num'] + 1 : 1;
108 2
                $page->enforce('sitemap-'.$category.($num > 1 ? '-'.$num : '').'.xml');
109 2
                $sitemap = new self();
110 2
                $xml = array();
111 2
                $offset = ($num > 1) ? (($num - 1) * $limit) - 1 : 0;
112 2
                if ($stmt = $sitemap->db->query(array(
113 2
                    'SELECT m.path, m.updated',
114 2
                    'FROM sitemap AS m',
115 2
                    'INNER JOIN categories AS c ON m.category_id = c.id',
116 2
                    'WHERE c.category LIKE ?',
117 2
                    'ORDER BY m.path ASC',
118 2
                    'LIMIT '.$offset.', '.$limit,
119 2
                ), $category.'%', 'row')) {
0 ignored issues
show
Documentation introduced by
$category . '%' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120 2
                    while (list($path, $updated) = $sitemap->db->fetch($stmt)) {
121 2
                        $last_modified = max($last_modified, $updated);
122 2
                        if (!empty($path)) {
123 2
                            $path .= $page->url['suffix'];
124 2
                        }
125 2
                        $xml[] = "\t".'<url>';
126 2
                        $xml[] = "\t\t".'<loc>'.$page->url['base'].$path.'</loc>';
127 2
                        $xml[] = "\t\t".'<lastmod>'.date('Y-m-d', $updated).'</lastmod>';
128 2
                        $xml[] = "\t".'</url>';
129 2
                    }
130 2
                    $sitemap->db->close($stmt);
131 2
                }
132 2
                unset($sitemap);
133 2
                if (empty($xml)) {
134 1
                    return new Response('', 404);
135
                }
136
                $xml = array(
137 2
                    '<?xml version="1.0" encoding="UTF-8"?>',
138 2
                    '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
139 2
                        implode("\n", $xml),
140 2
                    '</urlset>',
141 2
                );
142 2
            } else {
143 2
                $page->enforce('sitemap.xml');
144 2
                $sitemap = new self();
145 2
                $xml = array();
146 2
                $hier = new Hierarchy($sitemap->db, 'categories');
147 2
                $tree = $hier->tree(array('category'));
148 2
                $nest = $hier->nestify($tree);
149 2
                $flat = $hier->flatten($nest);
150 2
                unset($hier);
151 2
                foreach ($flat as $ids) {
152 2
                    if ($row = $sitemap->db->row('SELECT MAX(updated) AS updated, COUNT(*) AS count FROM sitemap WHERE category_id IN('.implode(', ', $ids).')', '', 'assoc')) {
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
153 2
                        $last_modified = max($last_modified, $row['updated']);
154 2
                        $updated = date('Y-m-d', $row['updated']);
155 2
                        $category = $tree[array_shift($ids)]['category'];
156 2
                        for ($i = 1; $i <= $row['count']; $i += $limit) {
157 2
                            $num = ceil($i / $limit);
158 2
                            $num = ($num > 1) ? '-'.$num : '';
159 2
                            $xml[] = "\t".'<sitemap>';
160 2
                            $xml[] = "\t\t".'<loc>'.$page->url['base'].'sitemap-'.$category.$num.'.xml</loc>';
161 2
                            $xml[] = "\t\t".'<lastmod>'.$updated.'</lastmod>';
162 2
                            $xml[] = "\t".'</sitemap>';
163 2
                        }
164 2
                    }
165 2
                }
166 2
                unset($sitemap);
167 2
                if (empty($xml)) {
168 1
                    return new Response('', 404);
169
                }
170
                $xml = array(
171 2
                    '<?xml version="1.0" encoding="UTF-8"?>',
172 2
                    '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
173 2
                        implode("\n", $xml),
174 2
                    '</sitemapindex>',
175 2
                );
176
            }
177
178 2
            return Asset::dispatch('xml', array($last_modified => implode("\n", $xml), 'expires' => $expires));
179
        } else {
180
            $page->filter('response', function ($page, $response, $type) {
181 1
                if ($type == 'html') {
182 1
                    $sitemap = new Component();
183 1
                    $sitemap->delete($page->url['path']);
184 1
                    unset($sitemap);
185 1
                }
186 1
            }, 404);
187
188 1
            return false;
189
        }
190
    }
191
192
    /**
193
     * Includes the current page in the sitemap if it's an html page and has no query string.
194
     * 
195
     * @param string $category The type of link you are saving, whatever you want to call it.  This allows you to segregate your search results if desired.
196
     * @param string $content  The main body of your page.
197
     * @param array  $save     Any other additional information that you consider to be important, and would like available to you when delivering search results.
198
     * 
199
     * @return null
200
     */
201 1
    public static function add($category, $content, array $save = array())
202
    {
203 1
        $page = Page::html();
204 1
        if ($page->url['format'] != 'html') {
205 1
            return;
206
        }
207 1
        $page->filter('response', function ($page, $response) use ($category, $content, $save) {
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
208 1
            if (empty($page->url['query'])) {
209 1
                $sitemap = new Component();
210 1
                $sitemap->upsert($category, array_merge(array(
211 1
                    'path' => $page->url['path'],
212 1
                    'title' => $page->title,
213 1
                    'description' => $page->description,
214 1
                    'keywords' => $page->keywords,
215 1
                    'thumb' => $page->thumb,
216 1
                    'content' => $content,
217 1
                ), $save));
218 1
                unset($sitemap);
219 1
            }
220 1
        }, array('html', 200));
221 1
    }
222
223
    /**
224
     * Call this when you ``$this->upsert()`` everything so that you can ``$this->delete()`` any missing links after.
225
     * 
226
     * @param string $category The sitemap section you are working on.
227
     * 
228
     * @return null
229
     */
230 3
    public function reset($category)
231
    {
232 3
        if ($ids = $this->db->ids('SELECT id FROM categories WHERE category LIKE ?', $category.'%')) {
0 ignored issues
show
Documentation introduced by
$category . '%' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
233 1
            $this->db->exec('UPDATE sitemap SET deleted = 1 WHERE category_id IN('.implode(', ', $ids).')');
234 1
        }
235 3
    }
236
237
    /**
238
     * This is to upsert multiple links into the Sitemap database all at once.
239
     * 
240
     * @param string   $category The sitemap section you are working on.
241
     * @param string[] $save     An ``array(key => value)`` pairs of data to save for each link.
242
     * The keys we are looking for are:
243
     * - '**category**' - To group and specify results.
244
     * - '**path**' - Of the url, without any suffix.
245
     * - '**title**' - Of the page.
246
     * - '**description**' - The meta description.
247
     * - '**keywords**' - A comma-separated list of tags.
248
     * - '**thumb**' - An image url for generating a thumbnail image.
249
     * - '**content**' - The main content section of the page.  We ``strip_tags()`` in house for searching, but deliver the original content with your search results.
250
     * 
251
     * @return null
252
     */
253 5
    public function upsert($category, array $save)
254
    {
255 5
        $sitemap = array();
256 5
        $save['category'] = $category;
257 5
        $updated = (isset($save['updated']) && is_numeric($save['updated'])) ? $save['updated'] : time();
258 5
        unset($save['updated']);
259 5
        foreach (array('category', 'path', 'title', 'description', 'keywords', 'thumb', 'content') as $value) {
260 5
            $sitemap[$value] = (isset($save[$value])) ? $save[$value] : '';
261 5
            unset($save[$value]);
262 5
        }
263 5
        $sitemap['info'] = serialize($save);
264 5
        $sitemap['hash'] = md5(implode('', $sitemap));
265 5
        $sitemap['updated'] = $updated;
266 5
        $sitemap['deleted'] = 0;
267 5
        extract($sitemap);
268 5
        if ($row = $this->exec('SELECT', 'sitemap', $path)) {
269 1
            if ($row['hash'] != $hash || $row['deleted'] = 1) {
270 1
                if ($row['hash'] == $hash) {
271 1
                    $updated = $row['updated']; // keep the former
272 1
                }
273 1
                $this->exec('UPDATE', 'search', array($path, $title, $description, $keywords, strip_tags($content), $row['docid']));
274 1
                $this->exec('UPDATE', 'sitemap', array($this->id($category), $path, $thumb, $info, $content, $hash, $updated, $deleted, $row['docid']));
275 1
            }
276 1
        } else {
277 4
            $docid = $this->exec('INSERT', 'search', array($path, $title, $description, $keywords, strip_tags($content)));
278 4
            $this->exec('INSERT', 'sitemap', array($docid, $this->id($category), $path, $thumb, $info, $content, $hash, $updated, $deleted));
279
        }
280 5
    }
281
282
    /**
283
     * Deletes a specific path (if specified), or everything that was not ``$this->upserted()`` after you ``$this->reset()``ed your sitemap links.
284
     * 
285
     * @param string $path  
286
     * 
287
     * @return null
288
     */
289 6
    public function delete($path = null)
290
    {
291 6
        if ($path) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
292 3
            if ($row = $this->exec('SELECT', 'sitemap', $path)) {
293 3
                $this->exec('DELETE', 'search', $row['docid']);
294 3
                $this->exec('DELETE', 'sitemap', $row['docid']);
295 3
            }
296 3
        } else {
297 3
            if ($stmt = $this->db->query('SELECT docid FROM sitemap WHERE deleted = ?', 1, 'assoc')) {
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
298 3
                while ($row = $this->db->fetch($stmt)) {
299 1
                    $this->exec('DELETE', 'search', $row['docid']);
300 1
                    $this->exec('DELETE', 'sitemap', $row['docid']);
301 1
                }
302 3
                $this->db->close($stmt);
303 3
            }
304
        }
305 6
    }
306
307
    /**
308
     * Gives you the total number of search results for the ``$phrase`` given.
309
     * 
310
     * @param string $phrase   The search term.
311
     * @param string $category A specific sitemap section.
312
     * @param string $where    Adds additional WHERE qualifiers to the query.  Prepend search table fields with an '**s.**', and sitemap table fields with an '**m.**'.
313
     * 
314
     * @return int The total count.
315
     */
316 3
    public function count($phrase, $category = '', $where = '')
317
    {
318 3
        return $this->db->fts->count('search', $phrase, $this->where($category, $where));
319
    }
320
321
    /**
322
     * Delivers the search results for the $phrase given form the most relevant to the least.
323
     * 
324
     * @param string      $phrase   The search term.
325
     * @param string      $category A specific sitemap section.
326
     * @param int|string  $limit    If you are not paginating results and only want the top whatever, then this is an integer.  Otherwise just pass the ``$pagination->limit`` LIMIT start, display string.
327
     * @param int|float[] $weights  An array of importance that you would like to place on the fields searched.  The order is: '**path**', '**title**', '**description**', '**keywords**', and '**content**'.  The default weights are ``array(1,1,1,1,1)``, every field being of equal importance.  If you only want to search the keywords, then you can specify ``array(0,0,0,1,0)``.  Please note that with this arrangement, the most relevant results will be returned first (with the search term being found among the keywords), but all of the other results will also be returned with a rank of 0 if the search term could be found anywhere else.
328
     * @param string      $where    Adds additional WHERE qualifiers to the query.  Prepend search table fields with an '**s.**', and sitemap table fields with an '**m.**'.
329
     * 
330
     * @return array An associative array of results.
331
     */
332 4
    public function search($phrase, $category = '', $limit = '', array $weights = array(), $where = '')
333
    {
334 4
        $page = Page::html();
335 4
        $fields = array('s.path', 's.title', 's.description', 's.keywords', 's.content AS search', 'c.category', 'm.path AS url', 'm.thumb', 'm.info', 'm.updated', 'm.content');
336 4
        $weights = array_slice(array_pad($weights, 5, 1), 0, 5);
337 4
        $search = $this->db->fts->search('search', $phrase, $limit, $this->where($category, $where), $fields, $weights);
338 4
        foreach ($search as $key => $row) {
339 4
            $row['words'] = $this->db->fts->offset($row, array('description', 'search', 'title', 'path', 'keywords'));
340 4
            if (!empty($row['url'])) {
341 4
                $row['url'] .= $page->url['suffix'];
342 4
            }
343 4
            $row['url'] = $page->url['base'].$row['url'];
344 4
            foreach (unserialize($row['info']) as $info => $value) {
345 4
                if (!isset($row[$info])) {
346 4
                    $row[$info] = $value;
347 4
                }
348 4
            }
349 4
            unset($row['search'], $row['info']);
350 4
            $row['snippet'] = strip_tags($row['snippet'], '<b>');
351 4
            $search[$key] = $row;
352 4
        }
353
354 4
        return $search;
355
    }
356
357
    /**
358
     * Once your search results are in, if you would like to know the specific word(s) which made a given page relevant, you may obtain them through this method. 
359
     * 
360
     * @param string $phrase The original search term.
361
     * @param int    $docid  The sitemap's docid which is returned with every search result.
362
     * 
363
     * @return string[] The unique search words found which made the $phrase relevant.
364
     */
365 2
    public function words($phrase, $docid)
366
    {
367 2
        return $this->db->fts->words('search', $phrase, $docid);
368
    }
369
370
    /**
371
     * Adds the category and additional parameters to a query string.
372
     * 
373
     * @param string $category 
374
     * @param string $and  
375
     * 
376
     * @return string
377
     */
378 4
    private function where($category, $and = '')
379
    {
380 4
        if (!empty($category)) {
381 4
            $sql = array();
382 4
            foreach ((array) $category as $like) {
383 4
                $sql[] = "c.category LIKE '{$like}%'";
384 4
            }
385 4
            $category = 'AND '.implode(' OR ', $sql);
386 4
        }
387
388 4
        return trim('INNER JOIN sitemap AS m INNER JOIN categories AS c WHERE s.docid = m.docid AND m.category_id = c.id '.$category.' '.$and);
389
    }
390
391
    /**
392
     * Converts a category string into it's id.
393
     * 
394
     * @param string $category 
395
     * 
396
     * @return int
397
     */
398 5
    private function id($category)
399
    {
400 5
        if (is_null($this->ids)) {
401 5
            $this->ids = array();
402 5
            $categories = $this->db->all('SELECT category, id FROM categories', '', 'assoc');
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
403 5
            foreach ($categories as $row) {
404 3
                $this->ids[$row['category']] = $row['id'];
405 5
            }
406 5
        }
407 5
        if (!isset($this->ids[$category])) {
408 4
            $parent = 0;
409 4
            $previous = '';
410 4
            foreach (explode('/', $category) as $path) {
411 4
                if (!isset($this->ids[$previous.$path])) {
412 4
                    $this->ids[$previous.$path] = $this->exec('INSERT', 'categories', array($previous.$path, $parent));
413 4
                }
414 4
                $parent = $this->ids[$previous.$path];
415 4
                $previous .= $path.'/';
416 4
            }
417 4
        }
418
419 5
        return $this->ids[$category];
420
    }
421
422
    /**
423
     * 
424
     * 
425
     * @param string        $action The type of query.
426
     * @param string        $table  The table to take $action on..
427
     * @param string|array  $values The appropriate values for a given query.
428
     * 
429
     * @return array|false|int
430
     */
431
    
432 6
    private function exec($action, $table, $values)
433
    {
434 6
        $action = strtolower($action);
435 6
        if (!isset($this->stmt[$action][$table])) {
436 6
            if ($this->transaction === false && $action != 'select') {
437 6
                $this->transaction = true;
438 6
                $this->db->exec('BEGIN IMMEDIATE');
439 6
            }
440
            switch ($action) {
441 6
                case 'select':
442 5
                    if ($table == 'sitemap') {
443 5
                        $stmt = $this->db->prepare('SELECT docid, hash, updated, deleted FROM sitemap WHERE path = ?', 'assoc');
444 5
                    }
445 5
                    break;
446 6
                case 'insert':
447 5
                    if ($table == 'search') {
448 4
                        $stmt = $this->db->insert('search', array('path', 'title', 'description', 'keywords', 'content'));
449 5
                    } elseif ($table == 'sitemap') {
450 4
                        $stmt = $this->db->insert('sitemap', array('docid', 'category_id', 'path', 'thumb', 'info', 'content', 'hash', 'updated', 'deleted'));
451 5
                    } elseif ($table == 'categories') {
452 4
                        $stmt = $this->db->insert('categories', array('category', 'parent'));
453 4
                    }
454 5
                    break;
455 5
                case 'update':
456 1
                    if ($table == 'search') {
457 1
                        $stmt = $this->db->update('search', 'docid', array('path', 'title', 'description', 'keywords', 'content'));
458 1
                    } elseif ($table == 'sitemap') {
459 1
                        $stmt = $this->db->update('sitemap', 'docid', array('category_id', 'path', 'thumb', 'info', 'content', 'hash', 'updated', 'deleted'));
460 1
                    }
461 1
                    break;
462 4
                case 'delete':
463 4
                    if ($table == 'search') {
464 4
                        $stmt = $this->db->prepare('DELETE FROM search WHERE docid = ?');
465 4
                    } elseif ($table == 'sitemap') {
466 4
                        $stmt = $this->db->prepare('DELETE FROM sitemap WHERE docid = ?');
467 4
                    }
468 4
                    break;
469
            }
470 6
            $this->stmt[$action][$table] = (isset($stmt)) ? $stmt : null;
471 6
        }
472 6
        $result = $this->db->execute($this->stmt[$action][$table], $values);
473 6
        if ($action == 'select') {
474 5
            $row = $this->db->fetch($this->stmt[$action][$table]);
475
476 5
            return (!empty($row)) ? $row : false;
477
        } else {
478 6
            return $result;
479
        }
480
    }
481
}
482