1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | use Mautic\Auth\ApiAuth; |
||
0 ignored issues
–
show
|
|||
6 | use Mautic\MauticApi; |
||
0 ignored issues
–
show
The type
Mautic\MauticApi was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
7 | |||
8 | require __DIR__.'/vendor/autoload.php'; |
||
9 | |||
10 | if ('cli' !== php_sapi_name()) { |
||
11 | die('This script can only run on the command line'); |
||
12 | } |
||
13 | |||
14 | $vars = [ |
||
15 | 1 => 'instanceUrl', |
||
16 | 2 => 'username', |
||
17 | 3 => 'password', |
||
18 | 4 => 'mauticVersion', |
||
19 | 5 => 'assetCategoryId', |
||
20 | 6 => 'fileToUpload', |
||
21 | ]; |
||
22 | |||
23 | foreach ($vars as $id => $var) { |
||
24 | if (empty($_SERVER['argv'][$id])) { |
||
25 | echo "Argument ${id} (${var}) is missing. Run this script as \"php upload.php ".implode(' ', $vars)."\"\n"; |
||
26 | exit(1); |
||
27 | } |
||
28 | |||
29 | $$var = $_SERVER['argv'][$id]; |
||
30 | } |
||
31 | |||
32 | // Set up the authentication |
||
33 | $settings = [ |
||
34 | 'userName' => $username, |
||
35 | 'password' => $password, |
||
36 | ]; |
||
37 | |||
38 | // Initiate the auth object specifying to use BasicAuth |
||
39 | $initAuth = new ApiAuth(); |
||
40 | $auth = $initAuth->newAuth($settings, 'BasicAuth'); |
||
41 | $api = new MauticApi(); |
||
42 | |||
43 | /** @var \Mautic\Api\Files */ |
||
44 | $filesApi = $api->newApi('files', $auth, $instanceUrl); |
||
45 | |||
46 | /** @var \Mautic\Api\Assets */ |
||
47 | $assetApi = $api->newApi('assets', $auth, $instanceUrl); |
||
48 | |||
49 | /** |
||
50 | * Upload the file. |
||
51 | */ |
||
52 | $filesApi->setFolder('assets'); |
||
53 | // File should be an absolute path! |
||
54 | $fileRequest = [ |
||
55 | 'file' => $fileToUpload, |
||
56 | ]; |
||
57 | |||
58 | $response = $filesApi->create($fileRequest); |
||
59 | |||
60 | if (isset($response['error'])) { |
||
61 | echo $response['error']['code'].': '.$response['error']['message']."\n"; |
||
62 | exit(1); |
||
63 | } |
||
64 | |||
65 | if (!isset($response['file']) || !isset($response['file']['name'])) { |
||
66 | echo 'An unknown error occurred while uploading the release asset to our Mautic instance. ' |
||
67 | ."Please try again or debug locally (we don't provide logs in CI for security reasons)\n"; |
||
68 | exit(1); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Create the actual asset based on the file we just uploaded. |
||
73 | */ |
||
74 | $data = [ |
||
75 | 'title' => "Mautic ${mauticVersion}", |
||
76 | 'storageLocation' => 'local', |
||
77 | 'file' => $response['file']['name'], |
||
78 | 'category' => $assetCategoryId, |
||
79 | 'isPublished' => false, |
||
80 | ]; |
||
81 | |||
82 | $response = $assetApi->create($data); |
||
83 | |||
84 | if (isset($response['error'])) { |
||
85 | echo $response['error']['code'].': '.$response['error']['message']."\n"; |
||
86 | exit(1); |
||
87 | } |
||
88 | |||
89 | if (!isset($response['asset']['id']) || !isset($response['asset']['downloadUrl'])) { |
||
90 | echo "Unknown error occurred while creating asset. Please debug locally.\n"; |
||
91 | exit(1); |
||
92 | } |
||
93 | |||
94 | echo 'Successfully created asset with ID '.$response['asset']['id']." 🚀\n"; |
||
95 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths