snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
10.92k stars 3.15k forks source link

Request : Do not increment when a tag is not auto-generated #8339

Open is984 opened 4 years ago

is984 commented 4 years ago

Server (please complete the following information):

Is your feature request related to a problem? Please describe. We use the auto-increment function of Snipe-IT to create asset tags. However, in rare cases, tags created outside of Snipe-IT are used. At that time, the auto-increment function works and the number is shifted.

Describe the solution you'd like I would like you to change it so that it is not automatically incremented when you use a tag that is not automatically generated.

Describe alternatives you've considered I think it is good to add a tag judgment function to the automatic increment function.

Additional context You could implement Observers.php as follows:. I am not good at English and cannot write the code according to the guideline, so I am suggesting this way. I'm sorry.

public function created(Asset $asset)
    {
        if ($settings = Setting::first()) {
                $current_tag ="";
                 if ($settings->zerofill_count > 0) {
                     $current_tag = $settings->auto_increment_prefix.Asset::zerofill($settings->next_auto_tag_base, $settings->zerofill_count);
                 }
                 else{  
                        $current_tag = $settings->auto_increment_prefix.$settings->next_auto_tag_base;
                 }

                if(str_slug($asset->asset_tag) == str_slug($current_tag)){
                        $settings->increment('next_auto_tag_base');
                }
        }

        $logAction = new Actionlog();
        $logAction->item_type = Asset::class;
        $logAction->item_id = $asset->id;
        $logAction->created_at =  date("Y-m-d H:i:s");
        $logAction->user_id = Auth::id();
        $logAction->logaction('create');

    }
stale[bot] commented 3 years ago

Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail. This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!

Cube38282 commented 1 year ago

Hello, I understand this is not a priority. we don't add new assets often, so a simple workaround cronjob script would suffice for now. Is there any way to set the next auto-increment directly in the db / files?