User imports with cron job - drupal

I have a drupal website where i wonna import user settings with a CSV ( Comma separate file ) file. I can do that with the user imports module. But this is manually. You need to choose a csv file and can then change some settings,... to import that file. That is no problem.
Now i wonna do that automaticly ( cron ? ). I have read that it could be done with the same user imports module. But i can't get it working. Somebody that can help me starting, to do the following.
So that he gonna see to an ftp location if there is a new csv file.
The he gonna do the import.
He must do changes for users that already exists an add new users if they doesn't exists. And for users that where deleted from the file , the user should set to inactive.
And after this, there should be a report with al the changes that are made

I would suggest using the feeds module. You can easily set it up to import on a schedule and can specify a local folder to look for new files. You can also set it up to access a remote url for the file, but only through http not ftp. We do a similar import and have a bash script that transfers the file to a local folder and then use feeds to import the resulting file.

Thanks for the advice. But i am rewriting the module into a new module. With everything i need. :)

Related

Drupal 8 to publish files

I'm trying to create a simple CMS to ingest contents and publish files. I'm using Drupal 8 with Feeds module to read xml files from a directory and it works fine.
I can't figure it out how I can take the information saved in my custom content and publish them to a file in another directory.
Anyone can help?
Thx
Luca
Could you create a view to render the desired output for the content you're after and then use the Views data export module to export that view into a file?
I note the following:
This module also exposes a drush command that can execute the view and
save its results to a file.
drush views-data-export [view-name] [display-id] [output-file]
If you can do it with Drush you can do it with PHP.
So potentially you could write hooks to manage the export of files based on the activity of the feed. E.g. The hook_ENTITY_TYPE_insert would allow you to perform logic when a node of a particular content type is created.

Importing Firebase database with changed to certain nodes

Is it possible to export the Firebase database and then make changes on an editor like Notepad and then import the database enforcing that only the changes made offline get updated?
For example, say I export the database today and add 6000 new child nodes through my notepad and then two days I import the database back to update it with the new nodes without affecting the other updates that have been made by my users.
What happens by default is that when I import the database it will rewrite every value that does not match. Hope I'm making sense.
As you can see from above image, firebase clearly says All data at this location will be overwritten, so you have to stop writing new data when you are updating the data by export and then import.
Now to recover such data, you can code that way to write upcoming data into json file or another database and stop writing it into firebase.
Hope this helps.
If you are using the Export JSON option from your Firebase Console, and than you make some offline changes on that file and than you use Import JSON option, no, it's not possible, because the new added file overrides the old one. So in other words, if you previously have made some changes, all the changes will be lost when you upload the modified file.
There are two options to solve this.
Stop to database for beeing written -> Export the file -> Make the changes -> Import the file.
and
Make all changes programmatically even if the database is changed by users.
Hope it helps.

Migrating Wordpress site to new domain

I have a Wordpress site with hostagator web hosting , I am buying new domain and want to use new domain for site but same existing developed site. How to backup existing site and then restore to new domain ?
Solution is here
after searching a lot i got one simple solution.
Using Duplicator plugins or any other tool is either difficult or paid.
My simple solution is as follows
Backup and download all data from public html folder
Download the SQL database associated with the wordpress site.(in phpMyadmin you will find option of export database.)
Now upload the same files of public html folder to the public html folder of new hosting.
create a database with same name and import the tables from the downloaded SQL database.(in phpMyadmin you will find option of import.)
Now check the site if the domain is not changed
If you are changing domain name too by keeping the website same you need to follow few more steps
Download and place the interconnet/it tool in public html folder and follow the steps in documentation to use this tool.
case1- you are transferring site from one domain to another
if you are transferring from abc.com to xyz.com ins search and replace tool replace abc.com string with xyz.com .
case2- if you are changing the names only in website
if you are keeping the domain same but changing name of site e.g. ABC Technologies to XYZ technologies . Then replace ABC to XYZ
You can use this tool as per your need as it is applicable for database too.
There are a lot of ways of doing that. You can search a lot of materials on Internet but I would advise you to use this tool because I used in the past and it's reliable and very straightforward.
It is called Duplicator and is a wordpress plugin solution:
https://wordpress.org/plugins/duplicator/
Consider to maintain your site active until your new site is working properly. I hope I could help you. Regards.
Just install WP migrate db plug-in in your current website. And export the database with your new URL. Then create a new database in your server and import the updated SQL file. Then edit your config.php with new database details. Finally point your new domian to this server
**should take complete backup (both files and databse) before making the above changes **
Here I will explain how to take back up manually and restore manually on another server with other domain name.
Backup: You need to take back up of site and database.
For site, you can take only back up of wp-content. It contains all data you need to resore.
STEP1 : cpanel-file manager-public html- (wp-content)- compress & save- export or
download zip file.
For database: phpmyadmin -> export databse. This gives you localhost.sql file.
These two files one .zip file and another .sql file are your back up.
(It is good to remember user id password of wordpress dashboard of this one)
Restore in another server on another domain:
After you get you new domain dns propagated on new server, open its cpanel.
Run wordpress script , see database name it is creating.
1) database restore:
MyphpAdmin->Database created by wordpress->check all tables->drop all tables.
Now your database is clean without any table.
In your loacalhost.sql file remove two piece of codes:
a)any signature like this (it should be on top)
-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
-- Host: localhost:3306
-- Generation Time: Oct 14, 2019 at 09:45 PM
-- Server version: 5.6.45
-- PHP Version: 7.2.7
b) Code prompting creating a new database like this:
-- Database: soniasin_fitfoody
CREATE DATABASE IF NOT EXISTS soniasin_fitfoody DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE soniasin_fitfoody;
-->Now, go to import and import, select your back up .sql file-> go. It will import all tables in your this database.
--> There is a database table now like wp_option, go there & edit siteurl (keep your new domain name), home (keep your new domain name) and admin email id.Very important.
Site Restoration:
1) Go to public html folder. Remove directory wp-content.
2) Import your back .zip file here and unzip.
3) You will find on wp-config.php file in public html folder, open it and update table prefix.
$table_prefix = 'wp_'; Here yo have to see what is your table prefix. Check database tables and see what prefix is in all tables. Here in this example it was 'wp_' , therefore kept it.
4) Now log in to you wordpress dashboard. It will take username of old site now and should take old password too. In case you forget password, change it and then open. Now wordpress will confirm that your database is changed, say ok and proceed.
Your site should be running on new URL now on another server.
In case of doubt, you ask me. If one want to watch any video here goes the link https://youtu.be/wROa37k_RQA.

how to specify drupal mail save file module's directory path?

I have installed above mentioned module.
It works fine, my doubt is how to mention current year in file directory field. Since, I would like to get mails saved in sub directories in format : year/month/date
Try writing your own hook_file_presave() function and hook file saving path:
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_file_presave/7.x
See what you have in that $file variable passed to the function, try somehow to detect that this module is saving the file and in that case change file path the way you want.

Wordpress File Upload Hook

I am trying to hook into the Wordpress file uploader and would like some suggestions. I would like to be able to grab the path of the source file (not WP path; i.e. K:\docs\file.pdf) so I can download another file of the same name (different extension) & path automatically (i.e. K:\docs\file.txt).
Wordpress provides hooks for after the file is uploaded but all path information at that point is internal to wordpress.
Thanks in advance!!
the path information can be obtained from normal php functions like pathinfo() and realpath() for example .
Bit too late to the party but I think what you are asking for is to find the source of the document in the clients system and based on that you want similar files there to be picked up by the browser and then sent to the user.
I think it will be a fairly complex thing to do, firstly you have to get the source of the document being added to the browser (I am not sure it can be done, but if it can be done then it will be via javascript) and then upload all the files one by one to the server hosting wordpress and you can do this by creating a custom page which will add the files uploaded to it as a wordpress attachment and then using something like jquery file uploader to upload files to that location.
But honestly, I think it would be a very complex thing, unless the client and the server are on the same machine.

Resources