Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core-ify "Random Keywords" plugin #2367

Merged
merged 15 commits into from
Oct 2, 2019
Merged

Conversation

dgw
Copy link
Member

@dgw dgw commented Feb 27, 2018

This is still WIP, don't merge yet. In particular, the check desired in #1877 for whether the standalone plugin is active doesn't do anything/might even crash the whole plugin (I've not tested it yet).

Mostly I'm looking for feedback on whether or not it's worth keeping the commit history of the original plugin. I did this with a merge using --allow-unrelated-histories. For the final PR, I can either prefix the merged-in commits with something so it's clear they pertain to the plugin, not YOURLS itself, or just remove the history and do a copy-paste import instead. What say you @ozh @LeoColomb?

Whatever the way forward, it's clear that having this functionality as a core plugin will (hopefully) reduce the number of issues/comments asking how to avoid sequential shorturls.

ozh and others added 7 commits January 27, 2014 19:31
Using str_shuffle means that each character can only occur once in the generated string. This reduces the number of permutations possible. For example, using base 36, and 4 characters, there are 36^4 = 1.68M, but the current function can only generate 36*35*34*33 = 1.41M of these. This alternative will use the whole range of possible strings.
Allow character to appear more than once
* Rename plugin and its functions
* Update README with new name
* Update license with current year
* Make plugin refuse to activate if the old 'Normal plugin' version
  is still active.
This was formerly an external plugin named `random-keywords`.

History from the `random-keywords` repo is kept.
@dgw dgw added enhancement New feature or request plugin This is an idea for a plugin. Anyone interested in making it? core labels Feb 27, 2018
@dgw dgw added this to the 1.8 milestone Feb 27, 2018
@dgw dgw self-assigned this Feb 27, 2018
@dgw dgw added the not ready label Feb 27, 2018
@ozh
Copy link
Member

ozh commented Feb 27, 2018

I for one really don't care about the git log and commit message history :) (I mean, nicely put commit messages are nice to have, but they shouldn't dictate the way one works)

@LeoColomb LeoColomb removed the wip label Mar 24, 2019
LeoColomb
LeoColomb previously approved these changes Sep 21, 2019
@dgw
Copy link
Member Author

dgw commented Sep 21, 2019

@LeoColomb I don't exactly remember what I still wanted to do with this. There was something, but I don't think I have time to look from a computer until tomorrow.

@LeoColomb
Copy link
Member

@dgw #1877 (comment)

(this would require a renaming of the functions and a check for previous version activated)

😉

@dgw
Copy link
Member Author

dgw commented Sep 21, 2019

Oh yeah. Maybe also a real option instead of $ozh_random_shorturl['length'] = 5; that needs to be edited in the file, since upgrading YOURLS would overwrite changes to that.

JensSpanier and others added 2 commits September 21, 2019 23:40
If strlen($possible) is for example 36, rand could also return 36.
But substr starts with position 0. So we have to subtract 1 from
strlen($possible).

----

Yoinked from YOURLS/random-keywords#10 by @dgw
@dgw
Copy link
Member Author

dgw commented Sep 22, 2019

So I had a bit of time tonight after all. There's already a "conflict preventer" function that checks if the old plugin is active. It might not actually prevent loading this one in that case; I haven't had a chance to test it. (Honestly, I've been unable to find much useful documentation about how hooks are supposed to work. Do I just return false?)

But I noticed there was a merged PR in the other repo and pulled in those changes (tiny one-liner), and implemented a settings page which should work. 🤞

@LeoColomb LeoColomb requested a review from ozh September 23, 2019 08:22
@ozh
Copy link
Member

ozh commented Sep 24, 2019

Yep, saw this PR, will have time to look at it tomorrow :)

@ozh
Copy link
Member

ozh commented Sep 25, 2019

Nope, won't work ...

There's a missing ( on line 40 : if yourls_is_active_plugin( 'random-keywords' ) should be if (yourls_is_active_plugin( 'random-keywords' )) 😄

Plus, I think checking with yourls_is_active_plugin() isn't foolproof enough: if someone has installed the plugin in directory 'random-keyword(no trailing s) orrandom-url-like-bitly`, will this work? I'm not sure how this works but I think it's based on the directory name.
I think a more foolproof way would be to check if function ozh_random_keyword() already exists

Also, it's hooked onto 'activated_random-shorturls' so I guess it will echo the warning after activation anyway, and you'll end up with both plugins enabled. I don't think we have something early enough before plugin activation

Maybe a simple way would be something like:

if (function_exists('ozh_random_keyword')) {
   yourls_add_notice('deactivate your plugin, it's obsolete') or something like this
} else {
    all the yourls_add_action and filter to actually register the newer plugin
} 

Thoughts ?

@dgw
Copy link
Member Author

dgw commented Sep 27, 2019

I was going to actually do some of this now, but I've run out of time. 😔 So it'll get done during the next block of free time I (think I) have.

Also, it's hooked onto 'activated_random-shorturls' so I guess it will echo the warning after activation anyway, and you'll end up with both plugins enabled.

The idea was to block activating the plugin entirely, but it looks like there's no hook capable of doing that. All of the plugin activation hooks run after the activation itself is already finalized. So, I'll have to overwrite that (stub) implementation with a different approach—probably based on detecting the old plugin's function name, yes.

There's a missing ( on line 40 : if yourls_is_active_plugin( 'random-keywords' ) should be if (yourls_is_active_plugin( 'random-keywords' )) 😄

I'm spending too much time in Python these days… 🤣 But replacing the conflict preventer as discussed above will eliminate this error anyway.

@dgw dgw dismissed LeoColomb’s stale review September 27, 2019 22:11

Code is nowhere close to ready, so having an approval on it is very misleading!

The conflict preventer function was broken anyway (ineffective logic AND
incorrect syntax)
@dgw
Copy link
Member Author

dgw commented Sep 29, 2019

There, @ozh, I think that's more like what you were suggesting. Better?

@ozh
Copy link
Member

ozh commented Oct 2, 2019

Hmm, still doesn't work: having old one activated and activating new one, I get the expected notice but the plugin is still activated :

Random ShortURLs plugin cannot function unless Random Keywords is removed first.
Plugin has been activated

Will look into it

@ozh
Copy link
Member

ozh commented Oct 2, 2019

Meh. I'm dumb. Works completely as expected. :-)

@ozh ozh merged commit c5a65b7 into YOURLS:master Oct 2, 2019
@dgw dgw deleted the core-ify_random_keywords branch October 2, 2019 22:25
LeoColomb added a commit to YOURLS/awesome that referenced this pull request Oct 3, 2019
Plugin integrated in the core
Ref YOURLS/YOURLS#2367
@ghost
Copy link

ghost commented Jan 22, 2020

@ozh Would it be possible to push a new release (e.g. v1.7.5) which includes this commit? It's been almost four months.

@ozh
Copy link
Member

ozh commented Jan 22, 2020

Totally. Will do this week-end

@OpNop
Copy link

OpNop commented Jan 28, 2020

Any update on this? I just installed YOURLS and am liking it, but just noticed that random urls wasn't there and the docs say to enable the bundled plugin (that's not in the 1.7.4 release)

@ozh
Copy link
Member

ozh commented Jan 29, 2020

Yeah, sorry for my lack of reaction, I'm awfully short on free time :)
Released! https://github.com/YOURLS/YOURLS/releases/tag/1.7.5

@ghost
Copy link

ghost commented Jan 29, 2020

@ozh Thanks! How long does it typically take for new versions to appear on YOURLS' Docker Hub page?

@LeoColomb
Copy link
Member

@whalehub It tipycally takes two days. It's done almost automatically, but some manual steps are required from outside of YOURLS team.

doronbehar added a commit to doronbehar/YOURLS that referenced this pull request Feb 11, 2020
* 'master' of https://github.com/YOURLS/YOURLS:
  Bump for next release
  Bump
  bumped version number (YOURLS#2595)
  Add vector version of YOURLS logo (YOURLS#2548)
  Trim overlong client information  (YOURLS#2574)
  Rearrange opencollective badges
  Add jsonp parameter in API as a fallback to match documentation (YOURLS#2567)
  Update plugin.php (YOURLS#2562)
  Fix composer warning about uppercase in require block (YOURLS#2557)
  Split test in 2 (YOURLS#2558)
  Core-ify "Random Keywords" plugin (YOURLS#2367)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request plugin This is an idea for a plugin. Anyone interested in making it?
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants