Issues (55)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

migrations/PkleindienstBlogSeriesMigration.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations;
4
5
use Exception;
6
use Illuminate\Support\Facades\DB;
7
use October\Rain\Database\Collection;
8
use October\Rain\Support\Facades\Schema;
9
use October\Rain\Database\ModelException;
10
use PKleindienst\BlogSeries\Models\Series;
11
use GinoPane\BlogTaxonomy\Models\Series as BlogTaxonomySeries;
12
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions\NoDataException;
13
14
/**
15
 * Class PkleindienstBlogSeriesMigration
16
 *
17
 * @package GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations
18
 */
19
class PkleindienstBlogSeriesMigration extends AbstractMigration
20
{
21
    const PLUGIN_NAME = 'PKleindienst.BlogSeries';
22
23
    private $migratedSeriesIds = [];
24
25
    /**
26
     * Migrate plugin data
27
     */
28
    protected function migratePlugin()
29
    {
30
        try {
31
            $this->migrateSeries();
32
33
            $this->migrateRelatedSeries();
34
35
            $this->migratePostSeries();
36
        } catch (Exception $exception) {
37
            $this->command->error($exception->getMessage());
38
39
            $this->rollbackSeries();
40
        }
41
    }
42
43
    /**
44
     * Rolls back the migration process
45
     */
46
    private function rollbackSeries()
47
    {
48
        if (!empty($this->migratedSeriesIds)) {
49
            $this->command->warn('Rolling back migration');
50
51
            BlogTaxonomySeries::whereIn('id', array_keys($this->migratedSeriesIds))->delete();
52
53
            $this->command->warn('Roll back complete');
54
        }
55
    }
56
57
    /**
58
     * Migrate general series data
59
     *
60
     * @throws NoDataException
61
     */
62
    private function migrateSeries()
63
    {
64
        $this->command->info('Migrating series');
65
66
        $series = $this->getSeries();
67
68
        foreach ($series as $seriesRecord) {
69
            $blogTaxonomySeries = new BlogTaxonomySeries();
70
71
            $blogTaxonomySeries->slug = $seriesRecord->slug;
72
            $blogTaxonomySeries->title = $seriesRecord->title;
73
            $blogTaxonomySeries->description = $seriesRecord->description;
74
75
            try {
76
                $blogTaxonomySeries->save();
77
            } catch (ModelException $exception) {
0 ignored issues
show
The class October\Rain\Database\ModelException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
78
                $blogTaxonomySeries->slug .= '-migrated';
79
                $blogTaxonomySeries->title .= ' (migrated)';
80
81
                $blogTaxonomySeries->save();
82
            }
83
84
            $this->command->line(
85
                sprintf(
86
                    'Series "%s" => Blog Taxonomy Series "%s" (#%d)',
87
                    $seriesRecord->title,
88
                    $blogTaxonomySeries->title,
89
                    $blogTaxonomySeries->id
90
                )
91
            );
92
93
            $this->migratedSeriesIds[$blogTaxonomySeries->id] = $seriesRecord->id;
94
        }
95
96
        $this->command->info('All series have been migrated' . PHP_EOL);
97
    }
98
99
    /**
100
     * Migrate related series
101
     */
102
    private function migrateRelatedSeries()
103
    {
104
        if (empty($this->migratedSeriesIds) || !Schema::hasTable('pkleindienst_blogseries_related')) {
105
            return;
106
        }
107
108
        $this->command->info('Migrating related series');
109
110
        $relatedSeries = DB::table('pkleindienst_blogseries_related')->get();
111
112
        if (!count($relatedSeries)) {
113
            $this->command->warn('No related series found' . PHP_EOL);
114
115
            return;
116
        }
117
118
        $migratedSeries = array_flip($this->migratedSeriesIds);
119
120
        DB::transaction(function () use ($relatedSeries, $migratedSeries) {
121
            foreach ($relatedSeries as $relationRecord) {
122
                $seriesId = $migratedSeries[$relationRecord->series_id];
123
                $relatedSeriesId = $migratedSeries[$relationRecord->related_id];
124
125
                DB::table('ginopane_blogtaxonomy_related_series')->insert(
126
                    ['series_id' => $seriesId, 'related_series_id' => $relatedSeriesId]
127
                );
128
129
                $this->command->line(
130
                    sprintf(
131
                        'Relation "#%d" => "#%d" added',
132
                        $seriesId,
133
                        $relatedSeriesId
134
                    )
135
                );
136
            }
137
        });
138
139
        $this->command->info('Related series have been migrated' . PHP_EOL);
140
    }
141
142
    /**
143
     * Migrate series assigned to posts
144
     */
145
    private function migratePostSeries()
146
    {
147
        if (empty($this->migratedSeriesIds)) {
148
            return;
149
        }
150
151
        if (!$this->command->confirm(
152
            'Do you want to assign newly created series to posts (already assigned Blog Taxonomy series will be overwritten)'
153
        )) {
154
            return;
155
        }
156
157
        $this->command->info('Migrating series assigned to posts');
158
159
        $migratedSeries = array_flip($this->migratedSeriesIds);
160
161
        DB::transaction(function () use ($migratedSeries) {
162
            foreach ($migratedSeries as $oldSeriesId => $newSeriesId) {
163
                if (DB::table('rainlab_blog_posts')
164
                    ->where('series_id', $oldSeriesId)
165
                    ->update(['ginopane_blogtaxonomy_series_id' => $newSeriesId])
166
                ) {
167
                    $this->command->line(
168
                        sprintf(
169
                            'Series "#%d" has been assigned to a post',
170
                            $newSeriesId
171
                        )
172
                    );
173
                };
174
            }
175
        });
176
177
        $this->command->info('Migrated series has been assigned' . PHP_EOL);
178
    }
179
180
    /**
181
     * @return Collection|Series[]
182
     *
183
     * @throws NoDataException
184
     */
185
    private function getSeries()
186
    {
187
        $series = Series::all();
188
189
        if (!count($series)) {
190
            throw new NoDataException('No series records found');
191
        }
192
193
        $this->command->warn(sprintf('%d series found', count($series)));
194
195
        return $series;
196
    }
197
}