Skip to content

A free open source IT asset/license management system

undo pint changes

Godfrey M3bd89794f48f
diff --git a/.ai/rules/app.md b/.ai/rules/app.md
index fe0b20f307..c557b0e38d 100644
--- a/.ai/rules/app.md
+++ b/.ai/rules/app.md
@@ -5,5 +5,10 @@ paths:
# App
+## Translations
+
+UI strings are translation keys in `resources/lang/en-US/general.php` and its sibling files. Always add a new key rather
+than hard-coding English in a view.
+
## Use trans(), never __()
Translate with `trans('admin/hardware/message.some_key')` using short dotted keys from `resources/lang/<locale>/`. Never use `__()` — it appears nowhere in this codebase. Add a new key rather than hard-coding English.
diff --git a/.ai/rules/boost/http-routes.md b/.ai/rules/boost/http-routes.md
new file mode 100644
index 0000000000..c52c4a6be0
--- /dev/null
+++ b/.ai/rules/boost/http-routes.md
@@ -0,0 +1,9 @@
+---
+paths:
+ - 'app/Http/**'
+ - 'routes/**'
+---
+
+## APIs & Eloquent Resources
+
+- For APIs, default to using Eloquent API Resources and API versioning unless existing API routes do not, then you should follow existing application convention.
diff --git a/.ai/rules/boost/livewire-views.md b/.ai/rules/boost/livewire-views.md
new file mode 100644
index 0000000000..3c7da70a6b
--- /dev/null
+++ b/.ai/rules/boost/livewire-views.md
@@ -0,0 +1,11 @@
+---
+paths:
+ - 'app/Livewire/**'
+ - 'resources/views/**'
+---
+
+# Livewire
+
+- Livewire allow to build dynamic, reactive interfaces in PHP without writing JavaScript.
+- You can use Alpine.js for client-side interactions instead of JavaScript frameworks.
+- Keep state server-side so the UI reflects it. Validate and authorize in actions as you would in HTTP requests.
diff --git a/.ai/rules/boost/migrations.md b/.ai/rules/boost/migrations.md
new file mode 100644
index 0000000000..7465749584
--- /dev/null
+++ b/.ai/rules/boost/migrations.md
@@ -0,0 +1,8 @@
+---
+paths:
+ - 'database/migrations/**'
+---
+
+## Database
+
+- When modifying a column, the migration must include all of the attributes that were previously defined on the column. Otherwise, they will be dropped and lost.
diff --git a/.ai/rules/boost/models-migrations.md b/.ai/rules/boost/models-migrations.md
new file mode 100644
index 0000000000..56f864d529
--- /dev/null
+++ b/.ai/rules/boost/models-migrations.md
@@ -0,0 +1,13 @@
+---
+paths:
+ - 'app/Models/**'
+ - 'database/migrations/**'
+---
+
+# Models Migrations
+
+- Laravel 12 allows limiting eagerly loaded records natively, without external packages: `$query->latest()->limit(10);`.
+
+### Models
+
+- Casts can and likely should be set in a `casts()` method on a model rather than the `$casts` property. Follow existing conventions from other models.
diff --git a/.ai/rules/boost/models.md b/.ai/rules/boost/models.md
new file mode 100644
index 0000000000..304063354a
--- /dev/null
+++ b/.ai/rules/boost/models.md
@@ -0,0 +1,8 @@
+---
+paths:
+ - 'app/Models/**'
+---
+
+### Model Creation
+
+- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, using `php artisan make:model --help` to check the available options.
diff --git a/.ai/rules/boost/tests.md b/.ai/rules/boost/tests.md
new file mode 100644
index 0000000000..4a97a6852c
--- /dev/null
+++ b/.ai/rules/boost/tests.md
@@ -0,0 +1,26 @@
+---
+paths:
+ - 'tests/**'
+---
+
+## Testing
+
+- When creating models for tests, use the factories for the models. Check if the factory has custom states that can be used before manually setting up the model.
+- Faker: Use methods such as `$this->faker->word()` or `fake()->randomDigit()`. Follow existing conventions whether to use `$this->faker` or `fake()`.
+- When creating tests, make use of `php artisan make:test [options] {name}` to create a feature test, and pass `--unit` to create a unit test. Most tests should be feature tests.
+
+# PHPUnit
+
+- This application uses PHPUnit for testing. All tests must be written as PHPUnit classes. Use `php artisan make:test --phpunit {name}` to create a new test.
+- If you see a test using "Pest", convert it to PHPUnit.
+- Every time a test has been updated, run that singular test.
+- When the tests relating to your feature are passing, ask the user if they would like to also run the entire test suite to make sure everything is still passing.
+- Tests should cover all happy paths, failure paths, and edge cases.
+- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files; these are core to the application.
+
+## Running Tests
+
+- Run the minimal number of tests, using an appropriate filter, before finalizing.
+- To run all tests: `php artisan test --compact`.
+- To run all tests in a file: `php artisan test --compact tests/Feature/ExampleTest.php`.
+- To filter on a particular test name: `php artisan test --compact --filter=testName` (recommended after making a change to a related file).
diff --git a/.ai/rules/index.md b/.ai/rules/index.md
index 386bd8d539..d3d7a92d67 100644
--- a/.ai/rules/index.md
+++ b/.ai/rules/index.md
@@ -7,6 +7,12 @@ Before planning or editing, find the row whose globs match the file's path and r
| app/Actions/** | .ai/rules/actions.md |
| app/Http/Controllers/Api/** | .ai/rules/api.md |
| app/** | .ai/rules/app.md |
+| app/Http/**, routes/** | .ai/rules/boost/http-routes.md |
+| app/Livewire/**, resources/views/** | .ai/rules/boost/livewire-views.md |
+| database/migrations/** | .ai/rules/boost/migrations.md |
+| app/Models/**, database/migrations/** | .ai/rules/boost/models-migrations.md |
+| app/Models/** | .ai/rules/boost/models.md |
+| tests/** | .ai/rules/boost/tests.md |
| app/Http/Controllers/** | .ai/rules/controllers.md |
| app/Livewire/** | .ai/rules/livewire.md |
| database/migrations/** | .ai/rules/migrations.md |
diff --git a/.ai/rules/tests.md b/.ai/rules/tests.md
index 6b967be128..2754577414 100644
--- a/.ai/rules/tests.md
+++ b/.ai/rules/tests.md
@@ -5,11 +5,22 @@ paths:
# Tests
+## Test environment uses array drivers
+
+Feature tests hit the database. The test environment uses `array` drivers for cache, session, and mail.
+
## Database refresh comes from the base TestCase
`Tests\TestCase` already applies `LazilyRefreshDatabase` and seeds settings via `InitializesSettings`. Do not add `RefreshDatabase`, `DatabaseTransactions`, or `DatabaseMigrations` to an individual test.
## Test methods are snake_case
Name test methods in snake_case: `test_page_renders()`, `test_requires_permission()`. Never camelCase.
+## UI GET routes need a render and a permission test
+
+Every UI GET route should have both a `test_page_renders` test and a `test_requires_permission` test.
+
## Authenticate API tests with actingAsForApi()
Use `$this->actingAsForApi($user)` in API tests and `$this->actingAs($user)` in UI tests.
+
+## Feature and unit test placement
+Feature tests live in `tests/Feature/`, grouped by the feature or resource under test. A resource with both API and web controllers splits its tests into `Api/` and `Ui/` subfolders matching the layer under test; cross-cutting feature-area suites stay flat in their folder. Unit tests live in `tests/Unit/`, grouped by the type under test (`Models/`, `Presenters/`, `Transformers/`...).
diff --git a/.ai/rules/views.md b/.ai/rules/views.md
index 0cd96cdaed..53e8a0c958 100644
--- a/.ai/rules/views.md
+++ b/.ai/rules/views.md
@@ -5,6 +5,11 @@ paths:
# Views
+## Translations
+
+UI strings are translation keys in `resources/lang/en-US/general.php` and its sibling files. Always add a new key rather
+than hard-coding English in a view.
+
## Use trans(), never __()
Translate with `trans('general.some_key')` using short dotted keys from `resources/lang/<locale>/`. Never use `__()` — it appears nowhere in this codebase. Add a new key rather than hard-coding English.
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
index b621974271..130969c374 100644
--- a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
@@ -48,8 +48,15 @@ class CheckoutablesCheckedOutInBulkListener
}
if ($shouldSendEmailToAlertAddress && Setting::getSettings()->admin_cc_email) {
+ // admin_cc_email is validated as a comma-separated list
+ // (email_array validator on the settings request). CheckoutableListener
+ // already explodes on comma before handing to Mail::to; this listener
+ // used to pass the raw string, which Symfony Mailer would treat as
+ // one recipient and reject as invalid. See #19426.
+ $recipients = array_filter(array_map('trim', explode(',', Setting::getSettings()->admin_cc_email)));
+
try {
- Mail::to(Setting::getSettings()->admin_cc_email)->send(new BulkAssetCheckoutMail(
+ Mail::to($recipients)->send(new BulkAssetCheckoutMail(
$event->assets,
$event->target,
$event->admin,
diff --git a/app/Rules/AlphaEncrypted.php b/app/Rules/AlphaEncrypted.php
index 92eb074e71..e13f677946 100644
--- a/app/Rules/AlphaEncrypted.php
+++ b/app/Rules/AlphaEncrypted.php
@@ -5,24 +5,22 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class AlphaEncrypted implements ValidationRule
{
use ValidatesAttributes;
-
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateAlpha($attributeName, $decrypted, 'ascii') && ! is_null($decrypted)) {
+ if (!$this->validateAlpha($attributeName, $decrypted, 'ascii') && !is_null($decrypted)) {
$fail(trans('validation.alpha', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php
index fc65f78306..c2c451b82b 100644
--- a/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php
+++ b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php
@@ -4,12 +4,13 @@ namespace App\Rules;
use App\Models\Statuslabel;
use Closure;
-use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;
-use Illuminate\Translation\PotentiallyTranslatedString;
+use Illuminate\Contracts\Validation\DataAwareRule;
+
class AssetCannotBeCheckedOutToNondeployableStatus implements DataAwareRule, ValidationRule
{
+
/**
* All of the data under validation.
*
@@ -17,6 +18,7 @@ class AssetCannotBeCheckedOutToNondeployableStatus implements DataAwareRule, Val
*/
protected $data = [];
+
/**
* Set the data under validation.
*
@@ -25,25 +27,25 @@ class AssetCannotBeCheckedOutToNondeployableStatus implements DataAwareRule, Val
public function setData(array $data): static
{
$this->data = $data;
-
return $this;
}
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
// Check to see if any of the assign-ish fields are set
- if ((isset($this->data['assigned_to'])) || (isset($this->data['assigned_user'])) || (isset($this->data['assigned_location'])) || (isset($this->data['assigned_asset'])) || (isset($this->data['assigned_type']))) {
+ if ((isset($this->data['assigned_to'])) || (isset($this->data['assigned_user'])) || (isset($this->data['assigned_location'])) || (isset($this->data['assigned_asset'])) || (isset($this->data['assigned_type']))) {
- if (($value) && ($label = Statuslabel::find($value)) && ($label->getStatuslabelType() != 'deployable')) {
+ if (($value) && ($label = Statuslabel::find($value)) && ($label->getStatuslabelType()!='deployable')) {
$fail(trans('admin/hardware/form.asset_not_deployable'));
}
}
+
}
}
diff --git a/app/Rules/DateEncrypted.php b/app/Rules/DateEncrypted.php
index 9025f7e70b..73d5cd1b3e 100644
--- a/app/Rules/DateEncrypted.php
+++ b/app/Rules/DateEncrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class DateEncrypted implements ValidationRule
@@ -15,14 +14,14 @@ class DateEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateDate($attributeName, $decrypted) && ! is_null($decrypted)) {
+ if (!$this->validateDate($attributeName, $decrypted) && !is_null($decrypted)) {
$fail(trans('validation.date', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/EmailEncrypted.php b/app/Rules/EmailEncrypted.php
index f957e5c0f7..cd0e4ad289 100644
--- a/app/Rules/EmailEncrypted.php
+++ b/app/Rules/EmailEncrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class EmailEncrypted implements ValidationRule
@@ -15,14 +14,14 @@ class EmailEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string, ?string=): PotentiallyTranslatedString $fail
+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateEmail($attribute, $decrypted, []) && ! is_null($decrypted)) {
+ if (!$this->validateEmail($attribute, $decrypted, []) && !is_null($decrypted)) {
$fail(trans('validation.email', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/IPEncrypted.php b/app/Rules/IPEncrypted.php
index 8bfc0cbba8..2d64546308 100644
--- a/app/Rules/IPEncrypted.php
+++ b/app/Rules/IPEncrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class IPEncrypted implements ValidationRule
@@ -15,14 +14,14 @@ class IPEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateIp($attributeName, $decrypted) && ! is_null($decrypted)) {
+ if (!$this->validateIp($attributeName, $decrypted) && !is_null($decrypted)) {
$fail(trans('validation.ip', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/IPv4Encrypted.php b/app/Rules/IPv4Encrypted.php
index a46e1c3833..57f36da49a 100644
--- a/app/Rules/IPv4Encrypted.php
+++ b/app/Rules/IPv4Encrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class IPv4Encrypted implements ValidationRule
@@ -15,14 +14,14 @@ class IPv4Encrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateIpv4($attributeName, $decrypted) && ! is_null($decrypted)) {
+ if (!$this->validateIpv4($attributeName, $decrypted) && !is_null($decrypted)) {
$fail(trans('validation.ipv4', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/IPv6Encrypted.php b/app/Rules/IPv6Encrypted.php
index bbae8db952..6bb44fb2d9 100644
--- a/app/Rules/IPv6Encrypted.php
+++ b/app/Rules/IPv6Encrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class IPv6Encrypted implements ValidationRule
@@ -15,14 +14,14 @@ class IPv6Encrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateIpv6($attributeName, $decrypted) && ! is_null($decrypted)) {
+ if (!$this->validateIpv6($attributeName, $decrypted) && !is_null($decrypted)) {
$fail(trans('validation.ipv6', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/MacEncrypted.php b/app/Rules/MacEncrypted.php
index d3be5ed2c4..c9b125a900 100644
--- a/app/Rules/MacEncrypted.php
+++ b/app/Rules/MacEncrypted.php
@@ -2,10 +2,10 @@
namespace App\Rules;
+use App\Models\CustomField;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class MacEncrypted implements ValidationRule
@@ -15,14 +15,14 @@ class MacEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateRegex($attributeName, $decrypted, ['/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/']) && ! is_null($decrypted)) {
+ if (!$this->validateRegex($attributeName, $decrypted, ['/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/']) && !is_null($decrypted)) {
$fail(trans('validation.mac_address', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/NumericEncrypted.php b/app/Rules/NumericEncrypted.php
index b8b7f56bf1..abd34916e7 100644
--- a/app/Rules/NumericEncrypted.php
+++ b/app/Rules/NumericEncrypted.php
@@ -3,9 +3,10 @@
namespace App\Rules;
use Closure;
+use Egulias\EmailValidator\Validation\RFCValidation;
+use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class NumericEncrypted implements ValidationRule
@@ -15,14 +16,14 @@ class NumericEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateNumeric($attributeName, $decrypted, []) && ! is_null($decrypted)) {
+ if (!$this->validateNumeric($attributeName, $decrypted, []) && !is_null($decrypted)) {
$fail(trans('validation.numeric', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/RegexEncrypted.php b/app/Rules/RegexEncrypted.php
index 47ea02fa00..db72cafa11 100644
--- a/app/Rules/RegexEncrypted.php
+++ b/app/Rules/RegexEncrypted.php
@@ -6,7 +6,6 @@ use App\Models\CustomField;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class RegexEncrypted implements ValidationRule
@@ -16,7 +15,7 @@ class RegexEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string, ?string=): PotentiallyTranslatedString $fail
+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
@@ -26,7 +25,7 @@ class RegexEncrypted implements ValidationRule
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateRegex($attributeName, $decrypted, [$regex]) && ! is_null($decrypted)) {
+ if (!$this->validateRegex($attributeName, $decrypted, [$regex]) && !is_null($decrypted)) {
$fail(trans('validation.regex', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/UniqueUndeleted.php b/app/Rules/UniqueUndeleted.php
index d0af846839..e53274ea8d 100644
--- a/app/Rules/UniqueUndeleted.php
+++ b/app/Rules/UniqueUndeleted.php
@@ -5,22 +5,21 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\ValidatorAwareRule;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Validator;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Contracts\Validation\DataAwareRule;
class UniqueUndeleted implements ValidationRule, ValidatorAwareRule
{
protected ?Validator $validator = null;
-
protected array $columns = [];
-
protected $data = [];
public function __construct(
- public string $table,
- string ...$columns,
- ) {
+ public string $table,
+ string ...$columns,
+ )
+ {
$this->columns = $columns;
}
@@ -28,7 +27,7 @@ class UniqueUndeleted implements ValidationRule, ValidatorAwareRule
{
$this->validator = $validator;
$this->data = $validator->getData();
- // TODO - can we somehow grab the ID of the route-model-bound object, and omit its ID?
+ //TODO - can we somehow grab the ID of the route-model-bound object, and omit its ID?
// to do that, we'd have to know _which_ parameter in the validator is actually the R-M-B'ed
// parameter. Or maybe we just change the function signature to let you specify it.
@@ -38,13 +37,13 @@ class UniqueUndeleted implements ValidationRule, ValidatorAwareRule
/**
* Run the validation rule.
*
- * @param Closure(string, ?string=): PotentiallyTranslatedString $fail
+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$query = DB::table($this->table)->whereNull('deleted_at');
- $query->where($this->columns[0], '=', $value); // the first column to check
- $translation_string = 'validation.unique_undeleted'; // the normal validation string for a single-column check
+ $query->where($this->columns[0], '=', $value); //the first column to check
+ $translation_string = 'validation.unique_undeleted'; //the normal validation string for a single-column check
foreach (array_slice($this->columns, 1) as $column) {
$translation_string = 'validation.two_column_unique_undeleted';
$query->where($column, '=', $this->data[$column]);
diff --git a/app/Rules/UrlEncrypted.php b/app/Rules/UrlEncrypted.php
index 5a7a5d1f35..61c5f51c90 100644
--- a/app/Rules/UrlEncrypted.php
+++ b/app/Rules/UrlEncrypted.php
@@ -5,7 +5,6 @@ namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Crypt;
-use Illuminate\Translation\PotentiallyTranslatedString;
use Illuminate\Validation\Concerns\ValidatesAttributes;
class UrlEncrypted implements ValidationRule
@@ -15,14 +14,14 @@ class UrlEncrypted implements ValidationRule
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
try {
$attributeName = trim(preg_replace('/_+|snipeit|\d+/', ' ', $attribute));
$decrypted = Crypt::decrypt($value);
- if (! $this->validateUrl($attributeName, $decrypted, []) && ! is_null($decrypted)) {
+ if (!$this->validateUrl($attributeName, $decrypted, []) && !is_null($decrypted)) {
$fail(trans('validation.url', ['attribute' => $attributeName]));
}
} catch (\Exception $e) {
diff --git a/app/Rules/UserCannotSwitchCompaniesIfItemsAssigned.php b/app/Rules/UserCannotSwitchCompaniesIfItemsAssigned.php
index b5ba48625f..b31bc91d1b 100644
--- a/app/Rules/UserCannotSwitchCompaniesIfItemsAssigned.php
+++ b/app/Rules/UserCannotSwitchCompaniesIfItemsAssigned.php
@@ -1,24 +1,23 @@
<?php
namespace App\Rules;
-
use App\Models\Setting;
+use App\Models\User;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
-use Illuminate\Translation\PotentiallyTranslatedString;
class UserCannotSwitchCompaniesIfItemsAssigned implements ValidationRule
{
/**
* Run the validation rule.
*
- * @param Closure(string): PotentiallyTranslatedString $fail
+ * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$user = request()->route('user');
- if (($value) && ($user->allAssignedCount() > 0) && (Setting::getSettings()->full_multiple_companies_support == '1')) {
+ if (($value) && ($user->allAssignedCount() > 0) && (Setting::getSettings()->full_multiple_companies_support=='1')) {
// Check for assets with a different company_id than the selected company_id
$user_assets = $user->assets()->where('assets.company_id', '!=', $value)->count();
diff --git a/app/Services/SnipeTranslator.php b/app/Services/SnipeTranslator.php
index 56843185d3..eb7a9eb044 100644
--- a/app/Services/SnipeTranslator.php
+++ b/app/Services/SnipeTranslator.php
@@ -16,13 +16,13 @@ use Illuminate\Translation\Translator;
*
* This method is called by the trans_choice() helper, which we *do* use a lot.
***************************************************************/
-class SnipeTranslator extends Translator
-{
- public static $legacy_translation_namespaces = [
- 'backup::', // Spatie backup uses 'legacy' locale names
+class SnipeTranslator extends Translator {
+
+ static $legacy_translation_namespaces = [
+ "backup::" //Spatie backup uses 'legacy' locale names
];
- // This is copied-and-pasted (almost) verbatim from Illuminate\Translation\Translator
+ //This is copied-and-pasted (almost) verbatim from Illuminate\Translation\Translator
public function choice($key, $number, array $replace = [], $locale = null)
{
$line = $this->get(
@@ -36,12 +36,11 @@ class SnipeTranslator extends Translator
$number = count($number);
}
- if (! isset($replace['count'])) {
+ if (!isset($replace['count'])) {
$replace['count'] = $number;
}
- $underscored_locale = str_replace('-', '_', $locale); // OUR CHANGE.
-
+ $underscored_locale = str_replace("-","_",$locale); // OUR CHANGE.
return $this->makeReplacements( // BELOW - that $underscored_locale is the *ONLY* modified part
$this->getSelector()->choose($line, $number, $underscored_locale), $replace
);
@@ -58,7 +57,7 @@ class SnipeTranslator extends Translator
if (preg_match("/^$namespace/", $key)) {
$modified_locale = Helper::mapBackToLegacyLocale($locale);
$changed_fallback = true;
- $this->fallback = 'en'; // TODO - should this be 'env-able'? Or do we just put our foot down and say 'en'?
+ $this->fallback = 'en'; //TODO - should this be 'env-able'? Or do we just put our foot down and say 'en'?
break;
}
}
@@ -67,7 +66,8 @@ class SnipeTranslator extends Translator
if ($changed_fallback) {
$this->fallback = $previous_fallback;
}
-
return $result;
}
-}
+
+
+}
\ No newline at end of file
diff --git a/app/Traits/DisablesDebugbar.php b/app/Traits/DisablesDebugbar.php
index 413647a897..839ffb0b97 100644
--- a/app/Traits/DisablesDebugbar.php
+++ b/app/Traits/DisablesDebugbar.php
@@ -2,14 +2,12 @@
namespace App\Traits;
-use Fruitcake\LaravelDebugbar\Facades\Debugbar;
-
trait DisablesDebugbar
{
public function disableDebugbar()
{
- if (class_exists(Debugbar::class)) {
- Debugbar::disable();
+ if (class_exists(\Fruitcake\LaravelDebugbar\Facades\Debugbar::class)) {
+ \Fruitcake\LaravelDebugbar\Facades\Debugbar::disable();
}
}
}
diff --git a/bootstrap/app.php b/bootstrap/app.php
index 057c8a84eb..f2801adf6f 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -1,10 +1,5 @@
<?php
-use App\Exceptions\Handler;
-use App\Http\Kernel;
-use Illuminate\Contracts\Debug\ExceptionHandler;
-use Illuminate\Foundation\Application;
-
/*
|--------------------------------------------------------------------------
| Create The Application
@@ -16,7 +11,7 @@ use Illuminate\Foundation\Application;
|
*/
-$app = new Application(
+$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
@@ -33,7 +28,7 @@ $app = new Application(
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
- Kernel::class
+ App\Http\Kernel::class
);
$app->singleton(
@@ -42,8 +37,8 @@ $app->singleton(
);
$app->singleton(
- ExceptionHandler::class,
- Handler::class
+ Illuminate\Contracts\Debug\ExceptionHandler::class,
+ App\Exceptions\Handler::class
);
/*
diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php
index beba2fac86..32a56f0fcf 100644
--- a/database/factories/AssetFactory.php
+++ b/database/factories/AssetFactory.php
@@ -5,9 +5,6 @@ namespace Database\Factories;
use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\CustomField;
-use App\Models\Company;
-use App\Models\Manufacturer;
-use App\Models\Category;
use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\Supplier;
diff --git a/database/migrations/2025_07_16_142036_clean_checkout_acceptances.php b/database/migrations/2025_07_16_142036_clean_checkout_acceptances.php
index 1651e9f078..b1b5a1c756 100644
--- a/database/migrations/2025_07_16_142036_clean_checkout_acceptances.php
+++ b/database/migrations/2025_07_16_142036_clean_checkout_acceptances.php
@@ -11,8 +11,8 @@ return new class extends Migration
public function up(): void
{
//
- // Artisan::call('snipeit:clean-checkout-acceptances');
- // Commenting this out to prevent crashing due to a missing deleted_at clause
+ //Artisan::call('snipeit:clean-checkout-acceptances');
+ // Commenting this out to prevent crashing due to a missing deleted_at clause
}
/**
diff --git a/database/migrations/2026_04_07_141412_add_locations_parent_id_index.php b/database/migrations/2026_04_07_141412_add_locations_parent_id_index.php
index 796fca1502..9c1a9ff830 100644
--- a/database/migrations/2026_04_07_141412_add_locations_parent_id_index.php
+++ b/database/migrations/2026_04_07_141412_add_locations_parent_id_index.php
@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('locations', function (Blueprint $table) {
- $table->index(['parent_id', 'deleted_at']);
+ $table->index(['parent_id','deleted_at']);
});
}
@@ -22,7 +22,7 @@ return new class extends Migration
public function down(): void
{
Schema::table('locations', function (Blueprint $table) {
- $table->dropIndex(['parent_id', 'deleted_at']);
+ $table->dropIndex(['parent_id','deleted_at']);
});
}
};
diff --git a/database/migrations/2026_04_07_141930_accessories_checkout_assigned_to_index.php b/database/migrations/2026_04_07_141930_accessories_checkout_assigned_to_index.php
index 1eff042df3..4e723570ef 100644
--- a/database/migrations/2026_04_07_141930_accessories_checkout_assigned_to_index.php
+++ b/database/migrations/2026_04_07_141930_accessories_checkout_assigned_to_index.php
@@ -12,7 +12,7 @@ return new class extends Migration
public function up(): void
{
Schema::table('accessories_checkout', function (Blueprint $table) {
- $table->index(['assigned_to', 'assigned_type']);
+ $table->index(['assigned_to','assigned_type']);
});
}
@@ -22,7 +22,7 @@ return new class extends Migration
public function down(): void
{
Schema::table('accessories_checkout', function (Blueprint $table) {
- $table->dropIndex(['assigned_to', 'assigned_type']);
+ $table->dropIndex(['assigned_to','assigned_type']);
});
}
};
diff --git a/resources/views/paginator/simple.php b/resources/views/paginator/simple.php
index 9981cc0104..9cecbd3d77 100755
--- a/resources/views/paginator/simple.php
+++ b/resources/views/paginator/simple.php
@@ -2,7 +2,7 @@
use Illuminate\Pagination\BootstrapPresenter;
-$presenter = new BootstrapPresenter($paginator);
+ $presenter = new BootstrapPresenter($paginator);
$trans = $environment->getTranslator();
?>
diff --git a/resources/views/paginator/slider.php b/resources/views/paginator/slider.php
index 927829dca6..0713368c6a 100755
--- a/resources/views/paginator/slider.php
+++ b/resources/views/paginator/slider.php
@@ -2,7 +2,7 @@
use Illuminate\Pagination\BootstrapPresenter;
-$presenter = new BootstrapPresenter($paginator);
+ $presenter = new BootstrapPresenter($paginator);
?>
<div class="pagination">
diff --git a/routes/console.php b/routes/console.php
index a4c876ae04..2413e4b189 100644
--- a/routes/console.php
+++ b/routes/console.php
@@ -20,7 +20,7 @@ Artisan::command('inspire', function () {
Artisan::command('snipeit:travisci-install', function () {
if (! Setting::setupCompleted()) {
- $settings = new Setting;
+ $settings = new Setting();
$settings->site_name = 'test-ci';
$settings->alert_email = '[email protected]';
$settings->alerts_enabled = 1;
diff --git a/server.php b/server.php
index 0d289eb0ed..f65c7c444f 100644
--- a/server.php
+++ b/server.php
@@ -3,8 +3,10 @@
/**
* Laravel - A PHP Framework For Web Artisans
*
+ * @package Laravel
* @author Taylor Otwell <[email protected]>
*/
+
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
diff --git a/upgrade.php b/upgrade.php
index 8186cf8aef..d2c62c530e 100644
--- a/upgrade.php
+++ b/upgrade.php
@@ -4,19 +4,18 @@ $error_icon = "\e[91m✘\e[0m";
$success_icon = "\e[92m√\e[0m";
$info_icon = "\e[93mⓘ\e[0m";
-(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && exit('Access denied.');
+(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
// We define this because we can't reliably use file_get_contents because some
// machines don't allow URL access via allow_url_fopen being set to off
-function url_get_contents($Url)
-{
+function url_get_contents ($Url) {
$results = file_get_contents($Url);
if ($results) {
return $results;
}
- echo "file_get_contents() failed, trying curl instead.\n";
- if (! function_exists('curl_init')) {
- exit("cURL is not installed!\nThis is required for Snipe-IT as well as the upgrade script, so you will need to fix this before continuing.\nAborting upgrade...\n");
+ print("file_get_contents() failed, trying curl instead.\n");
+ if (!function_exists('curl_init')){
+ die("cURL is not installed!\nThis is required for Snipe-IT as well as the upgrade script, so you will need to fix this before continuing.\nAborting upgrade...\n");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
@@ -25,19 +24,17 @@ function url_get_contents($Url)
// weird corporate environments.
// See: https://github.com/curl/curl/commit/2d6333101a71129a6a802eb93f84a5ac89e34479
// this will _probably_ only work if your libcurl has been linked to Schannel, the native Windows SSL implementation
- if (PHP_OS == 'WINNT' && defined('CURLOPT_SSL_OPTIONS') && defined('CURLSSLOPT_NATIVE_CA')) {
+ if (PHP_OS == "WINNT" && defined("CURLOPT_SSL_OPTIONS") && defined("CURLSSLOPT_NATIVE_CA")) {
curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
}
$output = curl_exec($ch);
curl_close($ch);
if ($output === false) {
- echo "\e[91mError retrieving PHP requirements!\e[39m\n";
- echo 'Error was: '.curl_error($ch)."\n";
- echo 'Try enabling allow_url_fopen in php.ini, or fixing your curl/OpenSSL setup, or try rerunning with --skip-php-compatibility-checks';
-
+ print("\e[91mError retrieving PHP requirements!\e[39m\n");
+ print("Error was: " . curl_error($ch) . "\n");
+ print("Try enabling allow_url_fopen in php.ini, or fixing your curl/OpenSSL setup, or try rerunning with --skip-php-compatibility-checks");
return '{}';
}
-
return $output;
}
@@ -49,8 +46,8 @@ $no_interactive = false;
$skip_backup = false;
// Check for branch or other overrides
-if ($argc > 1) {
- for ($arg = 1; $arg < $argc; $arg++) {
+if ($argc > 1){
+ for ($arg=1; $arg<$argc; $arg++){
switch ($argv[$arg]) {
case '--skip-php-compatibility-checks':
$skip_php_checks = true;
@@ -65,7 +62,7 @@ if ($argc > 1) {
break;
case '--no-interactive':
$no_interactive = true;
- putenv('COMPOSER_NO_INTERACTION=1'); // put composer in non-interactive mode aswell
+ putenv("COMPOSER_NO_INTERACTION=1"); //put composer in non-interactive mode aswell
break;
default: // for legacy support from before we started using --branch
$branch = $argv[$arg];
@@ -89,75 +86,79 @@ echo "- run a backup \n";
echo "- run migrations to get your schema up to date \n";
echo "- clear out old cache settings\e[39m\n\n";
+
// Fetching most current upgrade requirements from github. Read more here: https://github.com/grokability/snipe-it/pull/14127
$remote_requirements_file = "https://raw.githubusercontent.com/grokability/snipe-it/$branch/.upgrade_requirements.json";
$upgrade_requirements_raw = url_get_contents($remote_requirements_file);
$upgrade_requirements = json_decode($upgrade_requirements_raw, true);
if (! $upgrade_requirements) {
- if (! $skip_php_checks) {
+ if(!$skip_php_checks){
echo "\n\e[91mERROR: Failed to retrieve remote requirements from $remote_requirements_file \e[39m\n\n";
- if ($branch_override) {
+ if ($branch_override){
echo "\e[93mNOTE: You passed a custom branch: $branch\n";
echo "If the above URL doesn't work, that may be why. Please check the branch spelling/existence\e[39m\n\n";
}
if (json_last_error()) {
- echo "\e[91mJSON DECODE ERROR DETECTED:\n";
- echo json_last_error_msg()."\n\n";
- echo "Raw curl output:\n";
- echo $upgrade_requirements_raw."\e[39m\n\n";
+ print "\e[91mJSON DECODE ERROR DETECTED:\n";
+ print json_last_error_msg() . "\n\n";
+ print "Raw curl output:\n";
+ print $upgrade_requirements_raw . "\e[39m\n\n";
}
echo "\e[93mWe suggest correcting this, but if you can't, please verify that your requirements conform to those at that url.\n\n";
echo "\e[91m-- DANGER -- DO AT YOUR OWN RISK --\n";
echo "IF YOU ARE SURE, re-run this script with --skip-php-compatibility-checks to skip this check.\n";
echo "-- DANGER -- THIS COULD BREAK YOUR INSTALLATION\e[39m\n\n";
- exit("Aborting upgrade.\n\n");
+ die("Aborting upgrade.\n\n");
}
echo "\e[93mNOTICE: Unable to fetch upgrade requirements, but continuing because you passed --skip-php-compatibility-checks...e[39m\n";
}
echo "Launching using branch: $branch\e[39m\n";
-if ($upgrade_requirements) {
+if($upgrade_requirements){
$php_min_works = $upgrade_requirements['php_min_version'];
$php_max_wontwork = $upgrade_requirements['php_max_wontwork'];
echo "Found PHP requirements, will check for PHP > $php_min_works and < $php_max_wontwork\n";
}
// done fetching requirements
-if (! $no_interactive) {
+if (!$no_interactive) {
$yesno = readline("\nProceed with upgrade? [y/N]: ");
} else {
- $yesno = 'yes';
+ $yesno = "yes";
}
-if ($yesno == 'yes' || $yesno == 'YES' || $yesno == 'y' || $yesno == 'Y') {
- // don't do anything
+if ($yesno == "yes" || $yesno == "YES" ||$yesno == "y" ||$yesno == "Y"){
+ # don't do anything
} else {
- exit("Exiting.\n\n");
+ die("Exiting.\n\n");
}
echo "\n";
-if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (! function_exists('posix_getpwuid'))) {
- echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n";
+if ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') || (!function_exists('posix_getpwuid'))) {
+ echo "Skipping user check as it is not supported on Windows or Posix is not installed on this server. \n";
} else {
- $pwu_data = posix_getpwuid(posix_geteuid());
- $username = $pwu_data['name'];
+ $pwu_data = posix_getpwuid(posix_geteuid());
+ $username = $pwu_data['name'];
- if (($username == 'root') || ($username == 'admin')) {
- exit("\n".$error_icon."ERROR: This script should not be run as root/admin. Exiting.\n\n");
- }
+ if (($username=='root') || ($username=='admin')) {
+ die("\n".$error_icon."ERROR: This script should not be run as root/admin. Exiting.\n\n");
+ }
}
+
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 1: Checking .env file: \n";
echo "--------------------------------------------------------\e[39m\n\n";
+
// Check the .env looks ok
$env = file('.env');
-if (! $env) {
+if (! $env){
echo "\n\e[91m!!!!!!!!!!!!!!!!!!!!!!!!!! .ENV FILE ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "Your .env file doesn't seem to exist in this directory or isn't readable! Please look into that.\n";
exit(1);
@@ -169,22 +170,23 @@ $env_bad = '';
// Loop through each line of the .env
foreach ($env as $line_num => $line) {
- if ((strlen($line) > 1) && (strpos($line, '#') !== 0)) {
+ if ((strlen($line) > 1) && (strpos($line, "#") !== 0)) {
$env_line = explode('=', $line, 2);
if (count($env_line) != 2) {
continue;
}
- [$env_key, $env_value] = $env_line;
+ list ($env_key, $env_value) = $env_line;
// The array starts at 0
- $show_line_num = $line_num + 1;
+ $show_line_num = $line_num+1;
$env_value = trim($env_value);
// Strip out the quote marks if there are any
- $env_value = str_replace('"', '', $env_value);
- $env_value = str_replace("'", '', $env_value);
+ $env_value = str_replace('"', '',$env_value);
+ $env_value = str_replace("'", '',$env_value);
+
/**
* We set this $app_environment here to determine which version of composer to use, --no-dev or with dev dependencies.
@@ -197,14 +199,16 @@ foreach ($env as $line_num => $line) {
*
* We use this further down in the composer section of this upgrader.
*/
- if ($env_key == 'APP_ENV') {
+
+ if ($env_key == "APP_ENV") {
if ($env_value == 'production') {
$app_environment = 'production';
}
}
+
if ($env_key == 'APP_KEY') {
- if (($env_value == '') || (strlen($env_value) < 20)) {
+ if (($env_value=='') || (strlen($env_value) < 20)) {
$env_bad .= $error_icon." APP_KEY ERROR in your .env on line #'.{$show_line_num}.': Your APP_KEY should not be blank. Run `php artisan key:generate` to generate one.\n";
} else {
$env_good .= $success_icon." Your APP_KEY is not blank. \n";
@@ -213,34 +217,36 @@ foreach ($env as $line_num => $line) {
if ($env_key == 'APP_URL') {
- if (($env_value != 'null') && ($env_value != '')) {
+ if (($env_value!="null") && ($env_value!="")) {
$env_good .= $success_icon.' Your APP_URL is not null or blank. It is set to '.$env_value."\n";
- if (! str_begins(trim($env_value), 'http://') && (! str_begins($env_value, 'https://'))) {
+ if (!str_begins(trim($env_value), 'http://') && (!str_begins($env_value, 'https://'))) {
$env_bad .= $error_icon.' APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should start with https:// or http://!! It is currently set to: '.$env_value;
} else {
$env_good .= $success_icon.' Your APP_URL is set to '.$env_value.' and starts with the protocol (https:// or http://)'."\n";
}
- if (str_ends(trim($env_value), '/')) {
+ if (str_ends(trim($env_value), "/")) {
$env_bad .= $error_icon.' APP_URL ERROR in your .env on line #'.$show_line_num.': Your APP_URL should NOT end with a trailing slash. It is currently set to: '.$env_value;
} else {
$env_good .= $success_icon.' Your APP_URL ('.$env_value.') does not have a trailing slash.'."\n";
}
+
} else {
- $env_bad .= $error_icon.' APP_URL ERROR in your .env on line #'.$show_line_num.": Your APP_URL CANNOT be set to null or left blank.\n";
+ $env_bad .= $error_icon." APP_URL ERROR in your .env on line #".$show_line_num.": Your APP_URL CANNOT be set to null or left blank.\n";
}
}
+
}
}
echo $env_good;
-if ($env_bad != '') {
+if ($env_bad !='') {
echo "\e[91m!!!!!!!!!!!!!!!!!!!!!!!!!! .ENV FILE ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "\e[91mYour .env file is misconfigured. Upgrade cannot continue.\n";
@@ -253,20 +259,21 @@ if ($env_bad != '') {
exit(1);
}
-if (! $skip_php_checks) {
+
+if(!$skip_php_checks){
echo "\n\e[95m--------------------------------------------------------\n";
- echo 'STEP 2: Checking PHP requirements: (Required PHP >='.$php_min_works.' - <'.$php_max_wontwork.")\n";
+ echo "STEP 2: Checking PHP requirements: (Required PHP >=". $php_min_works. " - <".$php_max_wontwork.")\n";
echo "--------------------------------------------------------\e[39m\n\n";
if ((version_compare(phpversion(), $php_min_works, '>=')) && (version_compare(phpversion(), $php_max_wontwork, '<'))) {
- echo $success_icon.' Current PHP version: ('.phpversion().') is at least '.$php_min_works.' and less than '.$php_max_wontwork."! Continuing... \n";
+ echo $success_icon." Current PHP version: (" . phpversion() . ") is at least " . $php_min_works . " and less than ".$php_max_wontwork."! Continuing... \n";
echo sprintf("FYI: The php.ini used by this PHP is: %s\n\n", get_cfg_var('cfg_file_path'));
} else {
echo "\e[91m!!!!!!!!!!!!!!!!!!!!!!!!! PHP VERSION ERROR !!!!!!!!!!!!!!!!!!!!!!!!!\n";
- echo 'This version of PHP ('.phpversion().") is NOT compatible with Snipe-IT.\n";
- echo 'Snipe-IT requires PHP versions between '.$php_min_works.' and '.$php_max_wontwork.".\n";
+ echo "This version of PHP (".phpversion().") is NOT compatible with Snipe-IT.\n";
+ echo "Snipe-IT requires PHP versions between ".$php_min_works." and ".$php_max_wontwork.".\n";
echo "Please install a compatible version of PHP and re-run this script again. \n";
echo "\e[91m!!!!!!!!!!!!!!!!!!!!!!!!! ABORTING THE UPGRADER !!!!!!!!!!!!!!!!!!!!!!\n";
exit(1);
@@ -299,7 +306,7 @@ $required_exts_array =
$recommended_exts_array =
[
- 'sodium', // note that extensions need to be in BOTH the $required_exts_array and this one to be 'optional'
+ 'sodium', //note that extensions need to be in BOTH the $required_exts_array and this one to be 'optional'
];
$ext_missing = '';
$ext_installed = '';
@@ -308,13 +315,13 @@ $ext_installed = '';
foreach ($required_exts_array as $required_ext) {
// If we don't find the string in the array....
- if (! in_array($required_ext, $loaded_exts_array)) {
+ if (!in_array($required_ext, $loaded_exts_array)) {
// Let's check for any options with pipes in them - those mean you can have either or
if (strpos($required_ext, '|')) {
// Split the either/ors by their pipe and put them into an array
- $require_either = explode('|', $required_ext);
+ $require_either = explode("|", $required_ext);
$has_one_required_ext = false;
@@ -322,39 +329,39 @@ foreach ($required_exts_array as $required_ext) {
foreach ($require_either as $require_either_value) {
if (in_array($require_either_value, $loaded_exts_array)) {
- $ext_installed .= $success_icon.' '.$require_either_value." is installed!\n";
+ $ext_installed .= $success_icon.' '.$require_either_value." is installed!\n";
$has_one_required_ext = true;
break;
}
}
// If no match, add it to the string for errors
- if (! $has_one_required_ext) {
- $ext_missing .= $error_icon.' MISSING PHP EXTENSION: '.str_replace('|', ' OR ', $required_ext)."\n";
+ if (!$has_one_required_ext) {
+ $ext_missing .= $error_icon.' MISSING PHP EXTENSION: '.str_replace("|", " OR ", $required_ext)."\n";
break;
}
- // If this isn't an either/or option, just add it to the string of errors conventionally
- } elseif (! in_array($required_ext, $recommended_exts_array)) {
- $ext_missing .= $error_icon.' MISSING PHP EXTENSION: '.$required_ext."\n";
+ // If this isn't an either/or option, just add it to the string of errors conventionally
+ } elseif (!in_array($required_ext, $recommended_exts_array)){
+ $ext_missing .= $error_icon.' MISSING PHP EXTENSION: '.$required_ext."\n";
} else {
$ext_installed .= '- '.$required_ext." is *NOT* installed, but is recommended...\n";
}
- // The required extension string was found in the array of installed extensions - yay!
+ // The required extension string was found in the array of installed extensions - yay!
} else {
- $ext_installed .= $success_icon.' '.$required_ext." is installed!\n";
+ $ext_installed .= $success_icon.' '.$required_ext." is installed!\n";
}
}
// Print out a useful error message and abort the install
-if ($ext_missing != '') {
+if ($ext_missing!='') {
echo "--------------------------------------------------------\n";
echo "You have the following extensions installed: \n";
echo "--------------------------------------------------------\n";
foreach ($loaded_exts_array as $loaded_ext) {
- echo $success_icon.' '.$loaded_ext."\n";
+ echo $success_icon.' '.$loaded_ext."\n";
}
echo "\e[91m--------------------- !! ERROR !! ----------------------\n";
@@ -369,10 +376,13 @@ if ($ext_missing != '') {
}
+
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 3: Checking directory permissions: \n";
echo "--------------------------------------------------------\e[39m\n\n";
+
$writable_dirs_array =
[
'bootstrap/cache',
@@ -388,6 +398,13 @@ $writable_dirs_array =
'storage/app/backup-temp',
'storage/private_uploads',
'public/uploads',
+ // Livewire's composer post-install script publishes its dist assets
+ // to public/vendor/livewire. If this directory exists but isn't
+ // writable by the upgrade user, composer install fails mid-upgrade
+ // with a Flysystem UnableToWriteFile error and the install ends
+ // up half-upgraded.
+ 'public/vendor',
+ 'public/vendor/livewire',
];
$dirs_writable = '';
@@ -395,6 +412,13 @@ $dirs_not_writable = '';
// Loop through the directories that need to be writable
foreach ($writable_dirs_array as $writable_dir) {
+ // Skip directories that don't exist yet. A fresh install won't have
+ // public/vendor/livewire until the first composer install creates
+ // it, and is_writable returns false for non-existent paths, which
+ // would produce a misleading "not writable" error.
+ if (!file_exists($writable_dir)) {
+ continue;
+ }
if (is_writable($writable_dir)) {
$dirs_writable .= $success_icon.' '.getcwd().'/'.$writable_dir." is writable \n";
} else {
@@ -405,7 +429,7 @@ foreach ($writable_dirs_array as $writable_dir) {
echo $dirs_writable."\n";
// Print out a useful error message
-if ($dirs_not_writable != '') {
+if ($dirs_not_writable!='') {
echo "\e[91m--------------------------------------------------------\n";
echo "\eThe following directories/files do not seem writable: \n";
echo "\e--------------------------------------------------------\e[39m\n";
@@ -418,8 +442,11 @@ if ($dirs_not_writable != '') {
exit(1);
}
+
+
+
echo "\e[95m--------------------------------------------------------\n";
-echo 'STEP 4: Pulling latest from Git ('.$branch." branch): \n";
+echo "STEP 4: Pulling latest from Git (".$branch." branch): \n";
echo "--------------------------------------------------------\e[39m\n\n";
$git_version = shell_exec('git --version');
@@ -433,19 +460,19 @@ if ((strpos('git version', $git_version)) === false) {
if (count($remote_bits) != 2) {
continue;
}
- @[$url, $purpose] = explode(' ', $remote_bits[1]);
+ @list($url, $purpose) = explode(" ", $remote_bits[1]);
if (in_array($url, ['[email protected]:snipe/snipe-it.git', 'https://github.com/snipe/snipe-it.git'])) {
// SSH or HTTPS remotes
- $new_url = preg_replace('|snipe/snipe-it|', 'grokability/snipe-it', $url);
- echo $success_icon.' Resetting remote '.$remote_bits[0]." at $url to $new_url for purpose: $purpose\n";
+ $new_url = preg_replace("|snipe/snipe-it|", "grokability/snipe-it", $url);
+ echo $success_icon . " Resetting remote " . $remote_bits[0] . " at $url to $new_url for purpose: $purpose\n";
$push = '';
if ($purpose == '(push)') {
$push = '--push ';
}
- $cmd = "git remote set-url $push".$remote_bits[0].' '.$new_url;
+ $cmd = "git remote set-url $push" . $remote_bits[0] . " " . $new_url;
$remote_reset = shell_exec($cmd);
if ($remote_reset) {
- echo '-- '.$remote_reset."\n";
+ echo '-- ' . $remote_reset . "\n";
}
}
}
@@ -468,6 +495,7 @@ if ((strpos('git version', $git_version)) === false) {
}
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 5: Cleaning up old cached files:\n";
echo "--------------------------------------------------------\e[39m\n\n";
@@ -475,27 +503,28 @@ echo "--------------------------------------------------------\e[39m\n\n";
// Build an array of the files we generally want to delete because they
// can cause issues with funky caching
$unused_files = [
- 'bootstrap/cache/compiled.php',
- 'bootstrap/cache/services.php',
- 'bootstrap/cache/config.php',
- 'vendor/symfony/translation/TranslatorInterface.php',
+ "bootstrap/cache/compiled.php",
+ "bootstrap/cache/services.php",
+ "bootstrap/cache/config.php",
+ "vendor/symfony/translation/TranslatorInterface.php",
];
foreach ($unused_files as $unused_file) {
if (file_exists($unused_file)) {
- echo $success_icon.' Deleting '.$unused_file.". It is no longer used.\n";
+ echo $success_icon." Deleting ".$unused_file.". It is no longer used.\n";
@unlink($unused_file);
} else {
- echo $success_icon.' No '.$unused_file.", so nothing to delete.\n";
+ echo $success_icon." No ".$unused_file.", so nothing to delete.\n";
}
}
echo "\n";
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 6: Updating composer dependencies:\n";
echo "(This may take a moment.)\n";
echo "--------------------------------------------------------\e[39m\n\n";
-echo '-- Running the app in '.$app_environment." mode.\n";
+echo "-- Running the app in ".$app_environment." mode.\n";
// Composer install
if (file_exists('composer.phar')) {
@@ -529,6 +558,7 @@ if (file_exists('composer.phar')) {
$composer_dump = shell_exec('composer dump');
+
}
echo $composer_dump."\n";
@@ -547,30 +577,34 @@ echo "\n";
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 7: Putting application into maintenance mode: \n";
echo "--------------------------------------------------------\e[39m\n\n";
-exec('php artisan down', $down_results, $return_code);
-echo '-- '.implode("\n", $down_results)."\n";
+exec('php artisan down', $down_results, $return_code);
+echo '-- ' . implode("\n", $down_results) . "\n";
if ($return_code > 0) {
- exit("Something went wrong with downing your site. This can't be good. Please investigate the error and be sure to check https://snipe-it.readme.io/docs/common-issues and https://snipe-it.readme.io/docs/installation-issues for solutions to common upgrading issues. Aborting!\n\n");
+ die("Something went wrong with downing your site. This can't be good. Please investigate the error and be sure to check https://snipe-it.readme.io/docs/common-issues and https://snipe-it.readme.io/docs/installation-issues for solutions to common upgrading issues. Aborting!\n\n");
}
unset($return_code);
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 8: Backing up database: \n";
echo "--------------------------------------------------------\e[39m\n\n";
-if (! $skip_backup) {
+if (!$skip_backup) {
$backup = exec('php artisan snipeit:backup', $backup_results, $return_code);
if ($return_code > 0) {
- exit($error_icon." Something went wrong with your backup. Aborting!\n\n");
+ die($error_icon." Something went wrong with your backup. Aborting!\n\n");
} else {
- echo '-- '.implode("\n", $backup_results)."\n\n";
+ echo '-- ' . implode("\n", $backup_results) . "\n\n";
}
unset($return_code);
} else {
echo "Upgrade was run with --skip-backup, so no backup will be run.\n\n";
}
+
+
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 9: Migrating database:\n";
echo "--------------------------------------------------------\e[39m\n\n";
@@ -578,11 +612,13 @@ echo "--------------------------------------------------------\e[39m\n\n";
$migrations = shell_exec('php artisan migrate --force');
echo $migrations."\n";
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 10: Checking for OAuth keys:\n";
echo "--------------------------------------------------------\e[39m\n\n";
-if ((! file_exists('storage/oauth-public.key')) || (! file_exists('storage/oauth-private.key'))) {
+
+if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-private.key'))) {
echo $info_icon." No OAuth keys detected. Running passport install now.\n\n";
$passport = shell_exec('php artisan passport:install --no-interaction');
echo $passport;
@@ -590,6 +626,7 @@ if ((! file_exists('storage/oauth-public.key')) || (! file_exists('storage/oauth
echo $success_icon." OAuth keys detected. Skipping passport install.\n\n";
}
+
echo "\e[95m--------------------------------------------------------\n";
echo "STEP 11: Taking application out of maintenance mode:\n";
echo "--------------------------------------------------------\e[39m\n\n";
@@ -597,17 +634,18 @@ echo "--------------------------------------------------------\e[39m\n\n";
$up = shell_exec('php artisan up');
echo $success_icon.' '.trim($up)."\n\n";
+
+
echo "\e[92m---------------------- FINISHED! -----------------------\n";
echo "All done! Clear your browser cookies and re-login to use \n";
echo "your upgraded Snipe-IT!\n";
echo "--------------------------------------------------------\e[39m\n\n";
-function str_begins($haystack, $needle)
-{
- return substr_compare($haystack, $needle, 0, strlen($needle)) === 0;
+
+function str_begins($haystack, $needle) {
+ return (substr_compare($haystack, $needle, 0, strlen($needle)) === 0);
}
-function str_ends($haystack, $needle)
-{
- return substr_compare($haystack, $needle, -strlen($needle)) === 0;
+function str_ends($haystack, $needle) {
+ return (substr_compare($haystack, $needle, -strlen($needle)) === 0);
}