net_nehmer_static_interface::resolve_object_link()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 2
dl 0
loc 16
ccs 0
cts 10
cp 0
crap 30
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package net.nehmer.static
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use midcom\datamanager\datamanager;
10
11
/**
12
 * n.n.static MidCOM interface class.
13
 *
14
 * @package net.nehmer.static
15
 */
16
class net_nehmer_static_interface extends midcom_baseclasses_components_interface
17
implements midcom_services_permalinks_resolver
18
{
19
    /**
20
     * Iterate over all articles and create index record using the datamanager indexer method.
21
     */
22
    public function _on_reindex($topic, midcom_helper_configuration $config, midcom_services_indexer $indexer)
23
    {
24
        $qb = midcom::get()->dbfactory->new_query_builder(midcom_db_article::class);
25
        $qb->add_constraint('topic', '=', $topic->id);
26
27
        $datamanager = datamanager::from_schemadb($config->get('schemadb'));
0 ignored issues
show
Bug introduced by
It seems like $config->get('schemadb') can also be of type false; however, parameter $path of midcom\datamanager\datamanager::from_schemadb() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $datamanager = datamanager::from_schemadb(/** @scrutinizer ignore-type */ $config->get('schemadb'));
Loading history...
28
29
        foreach ($qb->execute() as $article) {
30
            try {
31
                $datamanager->set_storage($article);
32
            } catch (midcom_error $e) {
33
                $e->log(MIDCOM_LOG_WARN);
34
                continue;
35
            }
36
37
            net_nehmer_static_viewer::index($datamanager, $indexer, $topic);
38
        }
39
40
        return true;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function resolve_object_link(midcom_db_topic $topic, midcom_core_dbaobject $object) : ?string
47
    {
48
        if (!($object instanceof midcom_db_article)) {
49
            return null;
50
        }
51
        if ($object->topic != $topic->id) {
52
            return null;
53
        }
54
55
        $config = $this->get_config_for_topic($topic);
56
        if (   $object->name == 'index'
57
            && !$config->get('autoindex')) {
58
            return '';
59
        }
60
61
        return "{$object->name}/";
62
    }
63
64
    public function get_opengraph_default(midcom_core_dbaobject $object)
65
    {
66
        return 'article';
67
    }
68
}
69