Issues (52)

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.

Cron/Images.php (1 issue)

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 Stockbase\Integration\Cron;
4
5
use Magento\Catalog\Model\Product;
6
use Psr\Log\LoggerInterface;
7
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollection;
8
use Stockbase\Integration\StockbaseApi\Client\StockbaseClientFactory;
9
use Stockbase\Integration\Model\Config\StockbaseConfiguration;
10
use Stockbase\Integration\Model\ResourceModel\ProductImage as ProductImageResource;
11
use Stockbase\Integration\Helper\Images as ImagesHelper;
12
13
/**
14
 * Stockbase images synchronization cron job.
15
 */
16
class Images
17
{
18
    /**
19
     * @var LoggerInterface
20
     */
21
    private $logger;
22
    /**
23
     * @var StockbaseClientFactory
24
     */
25
    private $stockbaseClientFactory;
26
    /**
27
     * @var StockbaseConfiguration
28
     */
29
    private $config;
30
    /**
31
     * @var ProductImageResource
32
     */
33
    private $productImageResource;
34
    /**
35
     * @var ImagesHelper
36
     */
37
    private $imagesHelper;
38
    /**
39
     * @var ProductCollection
40
     */
41
    private $productCollection;
42
    /**
43
     * @var array
44
     */
45
    private $eans = array();
46
    
47
    /**
48
     * Images constructor.
49
     * @param LoggerInterface        $logger
50
     * @param StockbaseClientFactory $stockbaseClientFactory
51
     * @param StockbaseConfiguration $config
52
     * @param ProductCollection      $productCollection
53
     * @param ProductImageResource   $productImageResource
54
     * @param ImagesHelper           $imagesHelper
55
     */
56
    public function __construct(
57
        LoggerInterface $logger,
58
        StockbaseClientFactory $stockbaseClientFactory,
59
        StockbaseConfiguration $config,
60
        ProductCollection $productCollection,
61
        ProductImageResource $productImageResource,
62
        ImagesHelper $imagesHelper
63
    ) {
64
        $this->logger = $logger;
65
        $this->stockbaseClientFactory = $stockbaseClientFactory;
66
        $this->config = $config;
67
        $this->productCollection = $productCollection;
68
        $this->productImageResource = $productImageResource;
69
        $this->imagesHelper = $imagesHelper;
70
    }
71
72
    /**
73
     * Executes the job.
74
     */
75
    public function execute()
76
    {
77
        // validate configuration:
78
        if (!$this->config->isModuleEnabled() || !$this->config->isImagesSyncCronEnabled()) {
79
            return;
80
        }
81
        // start process:
82
        $this->logger->info('Synchronizing Stockbase images...');
83
        // get all the eans:
84
        $eans = $this->getEansToProcess();
85
        try {
86
            // if still need to process eans:
87
            if (count($eans) > 0) {
88
                $client = $this->stockbaseClientFactory->create();
89
                $images = $client->getImages($eans);
90
                // validate returned images:
91 View Code Duplication
                if (is_array($images->{'Items'}) && count($images->{'Items'}) > 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
                    // download and save the images locally:
93
                    $newImagesCount = $this->imagesHelper->saveProductImages($images->{'Items'}, $client);
94
                    $this->logger->info('New synchronized images: '.$newImagesCount);
95
                }
96
            }
97
        } catch (\Exception $e) {
98
            $this->logger->info('Cron runImageImport error: '.$e->getMessage());
99
            
100
            return;
101
        }
102
        $this->logger->info('Stockbase images synchronization complete.');
103
    }
104
105
    /**
106
     * @param Product $product
107
     */
108
    public function getProductEan($product)
109
    {
110
        // get ean attribute:
111
        $attribute = $this->config->getEanFieldName();
112
        // get ean:
113
        $ean = $product->getData($attribute);
114
        // if the ean is not empty:
115
        if ($ean) {
116
            // add the ean if this product has one:
117
            $this->eans[] = $ean;
118
        }
119
    }
120
121
    /**
122
     * @return array
123
     */
124
    private function getEansToProcess()
125
    {
126
        // clean eans list:
127
        $this->eans = array();
128
        // start process:
129
        $this->logger->info('Get All EANs');
130
        // get ean attribute:
131
        $attribute = $this->config->getEanFieldName();
132
        // validate attribute:
133
        if ($attribute) {
134
            // create collection and apply filters:
135
            $collection = $this->productCollection->create()
136
                ->addAttributeToSelect($attribute)
137
                ->addAttributeToSelect('stockbase_product')
138
                ->addAttributeToFilter('stockbase_product', array('eq' => '1')) // only stockbase products
139
                ->addAttributeToFilter($attribute, array('notnull' => true, 'neq' => '')) // not null and not empty ean
140
                ;
141
            // if the filter is active then exclude the eans processed:
142
            if ($this->config->filterProcessedProducts()) {
143
                // get eans list:
144
                $processedEans = $this->productImageResource->getProcessedEans();
145
                // add eans filter:
146
                if (count($processedEans) > 0) {
147
                    $this->logger->info('Filtered EANs: '.count($processedEans));
148
                    $collection->addAttributeToFilter($attribute, array('nin' => $processedEans));
149
                }
150
            }
151
            // walk collection and save eans in the object:
152
            $collection->walk(array($this, 'getProductEan'));
153
            // log eans count:
154
            $this->logger->info('EANs to process: '.count($this->eans));
155
        } else {
156
            // missing ean attribute:
157
            $this->logger->info('Please setup the EAN attribute.');
158
        }
159
        
160
        return $this->eans;
161
    }
162
}
163