Check DB Slug Dulplication
482234
public function uniqueSlug($slug_str, $tag_name)
	{
		$model = $this->tagModelString();
		if (!empty($slug_str) && $tag = $model::where('slug', $slug_str)->first()) {
			// 只有当 slug 一样但 tagname 不一样的情况下，才自动设置随机 slug 后缀
			if ($tag->name != $this->normalizeTagName($tag_name)) {
				$slug_str .= '-'. mt_rand(1000, 9999);
			}
		}
		return $slug_str;
	}
348469
public static function prefixSlug(string $slug) : string
    {
        if (substr($slug, 0, strlen(self::MODULE_PREFIX)) !== self::MODULE_PREFIX) {
            $slug = self::MODULE_PREFIX . $slug;
        }

        if (strlen($slug) > 20) {
            $slug = substr($slug, 0, 20);
        }

        $slug = strtolower($slug);

        return $slug;
    }
709865
public static function isExistBySlugType( $slug, $type, $config = [] ) {

		$model	= static::findBySlugType( $slug, $type, $config );

		return isset( $model );
	}
445680
private function checkSeoAttributes()
    {
        $model = $this->owner;
        $transliterationFunction = $this->transliterationFunction;

        // if slug field is empty, filling one with generated slug
        if ($this->slugAttribute && $model->{$this->slugAttribute} == null) {
            $model->{$this->slugAttribute} = $transliterationFunction($model->{$this->nameAttribute});
        }

        // if some seo field is empty, filling it with name field data
        foreach ($this->seoAttributes as $seoAttribute) {
            if ($model->{$seoAttribute} == null){
                $model->{$seoAttribute} = $model->{$this->nameAttribute};
            }
        }
    }
206292
function updateSlug($category,$slug,$title){
        if($slug!='')
            $slug= $this->str_slug($slug);
        else
            $slug= $this->str_slug($title);

        if($category->slug==$slug)
            return $slug;
        else
            return $this->checkSlugInCategories($slug);
    }
1363598
def maintain_slug
        postfix = nil
        total_count = 0

        while self.class.where(parent_id: parent_id, slug: "#{slug}#{postfix}").where("id != ?", id.to_i).exists? do
          total_count += 1
          postfix = "-#{total_count}"
        end

        if postfix
          self.slug = "#{slug}#{postfix}"
        end
      end
1329647
protected function getExistingSlugs($slug)
    {
        return static::where($this->slugOptions->slugField, 'LIKE', "{$slug}%")
            ->withoutGlobalScopes()// ignore scopes
            ->withTrashed()// trashed, when entry gets activated again
            ->orderBy($this->slugOptions->slugField)
            ->get()
            ->pluck($this->slugOptions->slugField);
    }
90952
def get_by_slug(slug):
        '''
        
        '''
        rec = TabTag.select().where(TabTag.slug == slug)
        if rec.count() > 0:
            return rec.get()
        return None
422590
def db_exists():
    """"""
    logger.info("Checking to see if %s already exists", repr(DB["NAME"]))
    try:
        # Hide stderr since it is confusing here
        psql("", stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError:
        return False
    return True
933255
def detect_version():
    """"""
    version_regex = re.compile(r'\(PostgreSQL\) (?P<major>\d)\.(?P<minor>\d)\.(?P<bugfix>\d)')
    pg_version = None
    with hide('running', 'stdout', 'stderr'):
        output = run('psql --version')
    match = version_regex.search(output)
    if match:
        result = match.groupdict()
        if 'major' in result and 'minor' in result:
            pg_version = u'%(major)s.%(minor)s' % result
    if not pg_version:
        abort(u"Error: Could not determine Postgres version of the server.")
    return pg_version
256451
private function checkUpdatingSlug($slug)
    {
        if ($this->id >= 1) {

            $found = false;
            foreach ($this->uniqueModels() as $class) {

                // find entries matching slug, exclude updating entry
                $builder = $this->eloqent($class)->where('slug', $slug);

                // same model - exlude check
                if ($class == self::class) {
                    $builder = $builder->where('id', '!=', $this->id);
                }

                // found same slug - break, need new slug
                if ($found = $builder->first()) {
                    break;
                }
            }

            // save to use current slug for update
            if ($found == false || $found == null) {
                return $slug;
            }
        }

        // new unique slug needed
        return false;
    }
955069
def validate_unique_slug(self, cleaned_data):
        
        date_kwargs = {}
        error_msg = _("The slug is not unique")

        # The /year/month/slug/ URL determines when a slug can be unique.
        pubdate = cleaned_data['publication_date'] or now()
        if '{year}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE:
            date_kwargs['year'] = pubdate.year
            error_msg = _("The slug is not unique within it's publication year.")
        if '{month}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE:
            date_kwargs['month'] = pubdate.month
            error_msg = _("The slug is not unique within it's publication month.")
        if '{day}' in appsettings.FLUENT_BLOGS_ENTRY_LINK_STYLE:
            date_kwargs['day'] = pubdate.day
            error_msg = _("The slug is not unique within it's publication day.")

        date_range = get_date_range(**date_kwargs)

        # Base filters are configurable for translation support.
        dup_filters = self.get_unique_slug_filters(cleaned_data)
        if date_range:
            dup_filters['publication_date__range'] = date_range

        dup_qs = EntryModel.objects.filter(**dup_filters)

        if self.instance and self.instance.pk:
            dup_qs = dup_qs.exclude(pk=self.instance.pk)

        # Test whether the slug is unique in the current month
        # Note: doesn't take changes to FLUENT_BLOGS_ENTRY_LINK_STYLE into account.
        if dup_qs.exists():
            raise ValidationError(error_msg)
373636
def is_current?
      ::Sequel.extension(:migration)
      ::Sequel::Migrator.is_current?(database, migration_directory)
    rescue => e
      raise ConnectionFailed, e
    end
958103
function guessSlug(wpPackage) {
  var directory = wpPackage.getPath();
  var slug = path.basename(directory);
  var slug2 = path.basename(path.dirname(directory));

  if ('trunk' === slug || 'src' === slug) {
    slug = slug2;
  } else if (-1 !== ['branches', 'tags'].indexOf(slug2)) {
    slug = path.basename(path.dirname(path.dirname(directory)));
  }

  return slug;
}
441787
def find_module(slug)
      modules.find { |m| m.slug.to_s == slug.to_s }
    end
998932
private function checkDB() {
		$res = $this->query('select * from sqlite_master where type=\'table\' and name=\'dropbox\'; ');
		if (! $res) {
			try {
				$this->DB->exec('create table '.$this->DB_TableName.'(path text, fname text, dat blob, isdir integer);');
				$this->DB->exec('create index nameidx on '.$this->DB_TableName.'(path, fname)');
				$this->DB->exec('create index isdiridx on '.$this->DB_TableName.'(isdir)');
			} catch (PDOException $e) {
				return $this->setError($e->getMessage());
			}
		}
		return true;
	}
300096
function checkSlugInCategories($slug){
        $repet=true;
        $counter=1;
        $newSlug=$slug;

        while ($repet)
        {
            if(Categories::where('slug',$newSlug)->where('model_type',$this->type)->first())
            {
                $newSlug=$slug.'-'.$counter;
                $counter++;
            }
            else
                $repet=false;
        }

        return $newSlug;
    }