mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #14816 from uberbrady/hotfix_autoincrement_workaround
Don't save next autoincrement base if it's going to fail, next
This commit is contained in:
commit
9fccafa3ac
|
@ -92,7 +92,7 @@ class AssetObserver
|
||||||
|
|
||||||
// only modify the 'next' one if it's *bigger* than the stored base
|
// only modify the 'next' one if it's *bigger* than the stored base
|
||||||
//
|
//
|
||||||
if($next_asset_tag > $settings->next_auto_tag_base) {
|
if ($next_asset_tag > $settings->next_auto_tag_base && $next_asset_tag < PHP_INT_MAX) {
|
||||||
$settings->next_auto_tag_base = $next_asset_tag;
|
$settings->next_auto_tag_base = $next_asset_tag;
|
||||||
$settings->save();
|
$settings->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use App\Models\AssetModel;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use App\Models\Setting;
|
||||||
|
|
||||||
class AssetTest extends TestCase
|
class AssetTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -135,6 +136,40 @@ class AssetTest extends TestCase
|
||||||
$this->assertEquals($final->asset_tag, $final_result);
|
$this->assertEquals($final->asset_tag, $final_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAutoIncrementBIG()
|
||||||
|
{
|
||||||
|
$this->settings->enableAutoIncrement();
|
||||||
|
|
||||||
|
// we have to do this by hand to 'simulate' two web pages being open at the same time
|
||||||
|
$a = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset()]);
|
||||||
|
$b = Asset::factory()->make(['asset_tag' => 'ABCD' . (PHP_INT_MAX - 1)]);
|
||||||
|
|
||||||
|
$this->assertTrue($a->save());
|
||||||
|
$this->assertTrue($b->save());
|
||||||
|
\Log::error("A asset tag is: " . $a->asset_tag);
|
||||||
|
$matches = [];
|
||||||
|
preg_match('/\d+/', $a->asset_tag, $matches);
|
||||||
|
\Log::error("digits are: " . $matches[0]);
|
||||||
|
$this->assertEquals(Setting::getSettings()->next_auto_tag_base, $matches[0] + 1, "Next auto increment number should be the last normally-saved one plus one, but isn't");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAutoIncrementAlmostBIG()
|
||||||
|
{
|
||||||
|
// TODO: this looks pretty close to the one above, could we maybe squish them together?
|
||||||
|
$this->settings->enableAutoIncrement();
|
||||||
|
|
||||||
|
// we have to do this by hand to 'simulate' two web pages being open at the same time
|
||||||
|
$a = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset()]);
|
||||||
|
$b = Asset::factory()->make(['asset_tag' => 'ABCD' . (PHP_INT_MAX - 2)]);
|
||||||
|
|
||||||
|
$this->assertTrue($a->save());
|
||||||
|
$this->assertTrue($b->save());
|
||||||
|
$matches = [];
|
||||||
|
preg_match('/\d+/', $b->asset_tag, $matches); //this is *b*, not *a* - slight difference from above test
|
||||||
|
$this->assertEquals(Setting::getSettings()->next_auto_tag_base, $matches[0] + 1, "Next auto increment number should be the last normally-saved one plus one, but isn't");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testWarrantyExpiresAttribute()
|
public function testWarrantyExpiresAttribute()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue