Joomla: regenerate aliases for all articles at once? - joomla

I am working on a Joomla 3.2.1 site and the client, without thinking, entered in the same alias for all articles, instead of letting the system use the article title. So now if I want to turn on SEF URL's we are going to have 404 issues in the future.
I want to resave or regenerate all article aliases at once (batch).
Is there a way to do it? in the MYSQL DB maybe?
Thank you in advance.

$alias = JApplication::stringURLSafe($article->title);

Joomla will generate the alias when saving the article. I am not aware of any batch joomla feature to regenerate all the aliases and I would also be interested to know about this.
If no other batch solution exists, you should do manually the updates to these fields.
In the database, you could run update queries for all your articles, but you must type each update query one by one.
The update query for a single row would look like:
UPDATE jos_content
SET alias='my-new-alias-name'
WHERE id='{id-of-the-article}'
For multiple rows at once, you could do something like this:
UPDATE jos_content
SET alias = CASE id
WHEN 1 THEN 'alias1'
WHEN 2 THEN 'alias2'
WHEN 3 THEN 'alias3'
END
WHERE id IN (1,2,3)

What you could do is delete the alias data from all of your articles in the database using mysql. Then make a tag, like "fixalias." Using the batch processing feature tag all of the articles with that tag.
This will run store() for all of your articles and automatically generate the aliases. Then delete the tag from the tag manager.you ar
A similar strategy would involve also deleting all the aliases but batch moving (don't copy) your articles to a temporary category and then moving them back.

Related

Rename a Parse Platform class

Does anyone in the Parse Platform community know if it's possible to rename a Parse class? E.g. I've got a class called Products and I'd like to rename it to Product.
Is this possible or do I need to do a full migration of all the data?
I found this github issue which was super helpful and lead me to the answer: https://github.com/parse-community/parse-server/issues/617
All I had to do was:
Rename the collection in the db (db.Products.renameCollection('Product')
Find the schema (db.getCollection("_SCHEMA").findOne({_id: "Products"})) and make a copy, update the _id and insert it.
Write a quick script to update all pointers in my Product records to point to className of "Product" rather than "Products".
Remove the old Products schema
Everything seems to be working as expected.

How to delete the ContentType and related db tables in Strapi?

I am using Strapi v3.0.0-beta.18.7
How to delete the ContentType and the related tables from DB ?
I tried the command below, but it is not deleting the db tables.
DELETE http://localhost:1337/content-type-builder/content-types/application::CONTENT_TYPE_NAME.CONTENT_TYPE_NAME
To delete the content-type and related db-tables in Strapi,
You can delete the folder inside /api folder having same name as your content-type
Suppose if you want to delete the "product" content type, you can delete the product folder inside of /api
The database's tables sync is not managed in the Content Type Builder plugin.
By default, Strapi doesn't delete anything from your database structure.
Strapi is customizable but you will not be able to update this.
Here is an issue that talks about this topic - https://github.com/strapi/strapi/issues/1114
The answers above are really helpful but don't explain, how you would actually go about deleting the table manually.
Suppose you run a local default installation with sqlite, you can find your database at .tmp/data.db. To connect to it, you will need a tool that you can get from sqlite directly:
https://sqlite.org/download.html
I guess you can add it to the PATH, but since I am a beginner and I just wanted it to work, i put the sqlite3.exe directly in the folder of the database and ran it.
To open the database, I used .open data.db and tested it with .tables which showed me all the tables that strapi created for me but didn't delete.
To ensure that I found the right table (recipe-cuisine) i looked at the content using .headers on followed by SELECT * FROM "recipe-cuisine";.
I finally deleted the whole table using DROP TABLE "recipe-cuisine";.
There is an awesome documentation on how to do other operations here: https://www.sqlitetutorial.net/
I hope that helps other beginners who struggle to delete the tables. If anybody has suggestions or helpful links with more information, that would be great!
Lets assume you need remove abc collection.
WARNING
Be sure you created backup and there are not other collections that contains abc substring.
Then you need execute commands:
DELETE FROM `users-permissions_permission` WHERE `controller` LIKE '%abc%';
DELETE FROM strapi_permission WHERE `subject` LIKE '%abc%';
DELETE FROM core_store WHERE `key` LIKE '%abc%';
DELETE FROM upload_file_morph WHERE related_type LIKE '%abc%';
DROP TABLE abc;
Then you need execute also:
rm -rf api/abc
Additional notes:
take care about plural names
be sure that there are no relations with other tables in other case you will see error
TypeError: Cannot read property 'globalId' of undefined

mutual exclusion in joomla

I created an extension for joomla using:
$id=$database->insertid();
I just covered that if two users are logged on to the site will fit together perform two records in the database and then this statement will return in both cases the same value.
in php you can solve this problem with the transactions.
In joomla how do I solve this problem?
If you have a table you are working with that extends JTable then make sure that you included the check out functionality that is optionally a part of that. THis must means adding a couple of fields like what is in the content table. This will prevent two people from editing the same row at the same time which creates a race condition in which one of the other will lose their data.
Please note that both php and joomla functions to return the last insert id rely on the mysql implementation, and mysql returns the last id inserted on the currently open connection so concurrency is not an issue
#iacoposk8 Your are right it might possible that in very rear case. Such time try to add current logged in user id in your sql query or any where so that it doesn't make any confict. I hope you get it what i want to say. Thanks

How can i insert a new article into joomla 2.5 database directly?

I am using Joomla 2.5 and want to insert 100 articles without using Joomla's article manager.
How can I achieve this?
This is incomplete. You also would need to add records to the assets table and to make sure that they are properly keyed to the content table and nesting within a category asset as well as the com_content asset. You can put all of the articles in the uncategorised category to handle that however.
Well, if I wanted to add 100 articles as quickly as possible, I would take a backup of the #__content table in the database, open it in Notepad++, add all my articles in and re-upload the table.
If you do this, don't forget to assign each article a different ID.

Dynamic table names in Doctrine

If I have tables in doctrine for user_1, user_2, etc. is there a way to dynamically set the table name in Doctrine for a single User model?
It's weird, I know. I'm trying to create an interface to a WordPress database (because WP has little to no API for directly accessing posts), and WP creates duplicate tables for each site, so there's a wp_posts, wp_comments, wp_2_posts, wp_2_comments, etc.
Here's what I ended up doing:
$post = new WordPressPost();
$post->setTableName('wp_'.$user_id.'_posts');
If it could, you would have to run migrations for each added/deleted user.
I am curious; why would you EVER need something like that?
I don't know how WP works, but here is the thing; each site should use it's OWN database, not to share it with others.

Resources