Giter Site home page Giter Site logo

bnomei / kirby3-autoid Goto Github PK

View Code? Open in Web Editor NEW
80.0 4.0 9.0 633 KB

Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.

Home Page: https://forum.getkirby.com/t/kirby3-autoid-plugin/23572

License: MIT License

PHP 99.50% JavaScript 0.50%
kirby3 kirby3-cms kirby3-plugin autoid tiny-url pages files incremental random uuid

kirby3-autoid's Introduction


Kirby 3.8 introduced UUIDs for pages, users and file with structures and block following soonish. My AutoID plugin will not yield you big benefits thereafter. If you need more performance with UUIDs consider using my Boost Plugin in combination with the core UUIDs.
 

Kirby 3 AutoID

Release Downloads Build Status Coverage Status Maintainability Twitter

Automatic unique ID for Pages, Files and nested Structures including performant helpers to retrieve them. Bonus: Tiny-URL.

Commerical Usage


Support open source!

This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?

Be kind. Share a little. Thanks.

‐ Bruno
 
M O N E Y
Github sponsor Patreon Buy Me a Coffee Paypal dontation Hire me

Wiki

Continue to the AutoID Wiki to read more on how to install, setup and use this plugin.

Similar

Kirby3-Boost Plugin which is like AutoID + Bolt and caching

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

kirby3-autoid's People

Contributors

bnomei avatar fabianmichael avatar gearsdigital avatar preya avatar tasinttttttt avatar tristantbg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kirby3-autoid's Issues

Weird behaviour + error

Bear with me as this is my first tryout with the autoid field!
As a test I've tried adding an autoid to the blueprint of an article by adding this to the content section:

autoid:
  type: hidden

Now I'm getting following error when I'm trying to save an article: Undefined offset: 9 at /site/plugins/kirby3-autoid/classes/AutoID.php:187.

I'm also noticing the autoid field is not getting popuplated, but the tags field is being screwed up:

- 
  value: |
    -
    value: |
    -
    value: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    text: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    autoid: 4iip2yyx
    text: |
    -
    value: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    text: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    autoid: 4iip2yyx
    autoid: hwddoq10
  text: |
    -
    value: |
    -
    value: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    text: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    autoid: 4iip2yyx
    text: |
    -
    value: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    text: |
    -
    value: nature
    text: nature
    autoid: sxo3u5xg
    -
    value: sky
    text: sky
    autoid: zuvv49hx
    -
    value: starts
    text: starts
    autoid: 99872gys
    -
    value: tree
    text: tree
    autoid: cyl5mgas
    autoid: 4iip2yyx
    autoid: hwddoq10
  autoid: av99gup1

FFR: the original field content was

Tags: nature, sky, starts, tree

Creates content file in multilanguage setup

Reference is this Thread

Multilanguage Setup (e.g. DE (default), EN)

  • Creating a page via the frontend (e.g. $page->createChild($mycontent)) while EN is current language.
  • Kirby creates new pages in default language only. Therefore the content file content.de.txt is created.
  • autoid kicks in via hook and adds the hidden field for the current language thereby creating content.en.txt (because EN is current language)

To create the content.en.txt file at that point is an unexpected side effect from the autoid plugin.

A solution could be to update only existing content files.

Support for structure fields in site.yml

As of right now, support for structure fields in site.yml is not supported, as it seems.

A common use case for me is to have site-wide definitions in structure fields in site.yml and reference them on other pages.

Do you want additional input for this?

Composer package version seems to be out of sync

The plugin version in this repo is 2.2.1 but I can't get nothing more than 1.4.x with a composer install (I clear my composer cache and try 2 times, still nothing).

I can't use \Bnomei\AutoID::index(true); to clear my cache (and I need it) since it's private in 1.4.x.

Thank you!

Call to undefined function $autoid()

Hey Bruno,
just added an autoid field to a file blueprint. got the following error after on field change:

[Thu Sep  6 21:19:18 2018] Error: Call to undefined function o2ebf0gz() in /vendor/bnomei/kirby3-autoid/classes/AutoID.php:154
Stack trace:
#0 /vendor/bnomei/kirby3-autoid/classes/AutoID.php(430): Bnomei\AutoID::removeEntry('o2ebf0gz')
#1 /vendor/bnomei/kirby3-autoid/config.php(70): Bnomei\AutoID::removeFile(Object(Kirby\Cms\File))
#2 [internal function]: Kirby\Cms\App->{closure}(Object(Kirby\Cms\File), Object(Kirby\Cms\File))
#3 /vendor/getkirby/cms/src/Cms/App.php(890): Closure->call(Object(Kirby\Cms\App), Object(Kirby\Cms\File), Object(Kirby\Cms\File))
#4 /vendor/getkirby/cms/src/Cms/FileActions.php(103): Kirby\Cms\App->trigger('file.update:aft...', Object(Kirby\Cms\File), Object(Kirby\Cms\File))
#5 /vendor/getkirby/cms/src/Cms/ModelWithContent.php(239): Kirby\Cms\File->commit('update', Array, Object(Closure))
#6 /vendor/getkirby/cms/config/api/routes/pages.php(104): Kirby\Cms\ModelWithContent->update(Array)
#7 [internal function]: Kirby\Api\Api->{closure}('sponsors', 'ddtxoajuqaa8flw...')
#8 /vendor/getkirby/cms/src/Api/Api.php(71): Closure->call(Object(Kirby\Api\Api), 'sponsors', 'ddtxoajuqaa8flw...')
#9 /vendor/getkirby/cms/src/Api/Api.php(264): Kirby\Api\Api->call('pages/sponsors/...', 'PATCH', Array)
#10 /vendor/getkirby/cms/config/routes.php(53): Kirby\Api\Api->render('pages/sponsors/...', 'PATCH', Array)
#11 [internal function]: Kirby\Http\Route->{closure}('pages/sponsors/...')
#12 /vendor/getkirby/cms/src/Cms/App.php(186): Closure->call(Object(Kirby\Http\Route), 'pages/sponsors/...')
#13 /vendor/getkirby/cms/src/Cms/App.php(572): Kirby\Cms\App->call('api/pages/spons...', 'PATCH')
#14 /public/index.php(34): Kirby\Cms\App->render()
#15 /public/router.php(12): include('/absPath...')
#16 {main}

modified-helper does not notice change in count

when caching a collection like $page->children() only existing objects are tracked.

this creates two bugs.

  • one when an objects is removed (easy to fix, will do)
  • another when an objects was added to the collection (no idea yet)

Use autoid as value in files and pages fields?

Is there any way to enable using autoid values in 'files' & 'pages' fields as described in the wiki for 'option' and 'select' fields by using, ie

files:
  type: files
  query:
    fetch: page.images
    value: "{{ file.AUTOID }}"

Duplicate autoid ?

I got a duplicate AutoID on two pages (they had the same one), is it possible ?
Does the plugin checks if the autoid already exists or not ?

undefined index name

i'm getting the following error in the response of my page after updating to the latest version (as well as latest kirby).

{"status":"error","exception":"Whoops\\Exception\\ErrorException","message":"Undefined index: name","file":"endor\/bnomei\/kirby3-autoid\/classes\/AutoID.php","line":178,"code":8}

ping me on slack if you want to see the request i'm sending ;)

Drafts aren't included

I'm not sure if it's an oversight or on purpose, but the plugin doesn't include drafts.
The initial indexing can be solved simply by using the index option you provide, like so:

'bnomei.autoid.index' => function ():\Kirby\Cms\Pages {
  return kirby()->site()->childrenAndDrafts()->index();
}

However, the find function uses Kirby's page helper function, which doesn't include drafts either. A simply fix would be to replace it with App::instance()->site()->findPageOrDraft().

If it is indeed on purpose. How do you feel about an option to include drafts?

Not working with date.handler strftime

If I have set my config to 'date.handler' => 'strftime', the plugin is not working. It gives an error:

Argument 6 passed to Bnomei\AutoID::commitEntry() must be of the type integer or null, string given, called in ../www/site/plugins/kirby3-autoid/classes/AutoID.php on line 186

Is there a way to use it with strftime?

Blueprints and snippets in docs

Nice work! :)

I think it will be helpful to have blueprint and snippet info in the docs as well, or at least point to them from the docs.

AUTOID doesn't take non-existing ids into account

I have a model in which I use AutoID to create custom page URLs. Simplified, it looks like this (the actualy URL is more complex):

<?php

class EventPage extends Page
{
    public function url($options = null): string
    {
        $url = $this->parent()->url() . '/' . $this->AUTOID();
        return Url::to($url, $options);
    }
}

When creating a page AutoID throws an error because it's trying to call autoid on null here:
https://github.com/bnomei/kirby3-autoid/blob/master/index.php#L82

This happens because we are a step before the AutoID is actually created. I'm not sure about the correct behaviour in general. But in my case I'd like AutoID so either return an empty string or null.

Feature Request: Nano ID generator

Thanks for the work! I'd really like to have a generator implementation based on nanoid. It's an amazing ID generator, which is in many cases faster than uuid and also uses a larger alphabet, so nanoids can be shorter than uuids. There's already a nanoid implementation in PHP. Since you used interfaces, this should be quite easy. I'm not a PHP developer, but if you like the feature idea, I might take the time to sit down and try to implement it in PHP.

Structure lost autoid value after blueprint changes

Question

  1. I have a blueprint with Structure containing Autoid field. IDs had been set.
  2. Then i removed autoid definition from blueprint and saved via panel.
  3. Later i added autoid field again and saved via panel.
  4. now i have different autoid value in structure fields than in step 1.

Answer
Because Structures only save fields defined in blueprint. Any additional fields will be removed on save. So you removed the previous IDs at step 2 yourself.
Unless you flushed you cache you might be able to recover them manually from the cache file in searching for the parent id of the structure.

Always null with structure field on users

I'm using structure field on users like that:

users/customer.yml

fields:
    addresses:
        label: Addresses
        type: structure
        translate: false
        fields:
            autoId:
                type: hidden
                translate: false

autoId always null:

Addresses:

- 
  autoid: null
  addresstype: shipping
  ...

Does translate: false work in structures?

I've tried to use translate: false in structures, yet, new autoids are created. When I think about, it would totally make sense it does not work, wouldn't know how references could be made between the languages.

Anyway…thx in advance for clarifying!

Multilanguage Setup doesn't create different Auto Ids

Hey guys,

I have a multilanguage Setup with two languages: DE and EN. EN ist the default language.

When I create a new page with the default language active and save the default language content file ist added an auto id. When I then switch the language and fill in content with the german laugage active and hit save, it saves the same auto id of the default language into the german content file.

When I first create the page in the German language and then translate everything in the English language everything works as expected and every language gets its own auto id.

Is this a bug?

Thank you very much for your help.

Best regards
Chris

$page->update not working with autoid

I have blueprint with an autoid field. If I try this:

$page = Page::create($props);
$page->update($newprops);

The updated fields are in the $page object, but the .txt file is not updated.

Problem is gone when I remove the autoid field.

"Call to a member function id() on null" when uploading files to dashboard

After installing AutoID plugin I get an error message when uploading files to dashboard (and working with those files).

Steps to reproduce:

  1. Install Kirby Plainkit with Composer
  2. Install Kirby AutoID plugin with Composer
  3. Add files section to site.yml blueprint
  4. Try to upload a file to the files section - the error message "Call to a member function id() on null" appears. When you close the message, the file is uploaded eventually.

Screenshot_2020-01-13 Site Title

The error message appears when I:

  • upload something in files section
  • upload something in textarea (through the "paperclip" button)
  • try to rename the file in the panel

This only happens while working in dashboard (site.yml blueprint).

I tried different versions of AutoID plugin. As far as I can tell, this behavior started with version 2.1.0.

PDOException on save

I thought I would never see this in Kirby. :)

image

I had to install the php-sqlite3 extension to make it work. But this got me wondering, does this plugin keep a list of ids? What if the cache folder is busted?

For example, I use Capistrano to deploy this particular Kirby project. Capistrano keeps a number of previous releases and I don't keep cache, media nor content in the repo. So on every deploy, all cache files are left with the previous release, starting out with a new cache after every deploy.

What does this mean for autoid? Will there be a loss of data?

Querying item from structure always yields first structure element

I have a structure field with an autoid, e.g. like so:

typologies:
  label:
    de: Typologien
    en: Typologies
  type: structure
  sortable: false
  sortBy: name asc
  fields:
    autoid:
      type: hidden
      translate: false
    name:
      label:
        de: Name
        en: Name
      type: text
    name_plural:
      label:
        de: Plural
        en: Plural
      type: text

and another select field which I fill with the structure values

typology_id:
  label:
    de: Typologie
    en: Typology
  type: select
  options: query
  query:
    fetch: site.children.template('products').first.typologies.toStructure
    text: "{{ structureItem.name }}"
    value: "{{ structureItem.autoid }}"

So then, the autoid gets saved as a key to the structure item.

When I try to retrieve the correct structure item with

autoid($page->typology_id())->name()

I always get the first item in the structure, not the saved one. Am I doing something wrong?

Thx!

Display autoid entries in panel pages sections

Is it possible to use autoid to filter pages to be displayed in a pages section inside a custom panel blueprint?

sections:
  mysection:
    headline: Foo Pages
    type: pages
    parent: autoid(page.autoid())

Notably the parent filter is limited in scope and there's a plugin to do more complex filtering. Is there a way to achieve a filtering based on autoid without using an additional plugin?

The `vendor` should not be under Git version control

As title, it looks like the vendor directory is under the Git version control.

However, the vendor directory is about the dependencies directory and this will be generated by running composer install command.

This directory should be removed and add this in the .gitignore file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.