Migrate users data from django to drupal 7 - django

Is there a way to migrate users data from django to drupal-7. I have 800 users in my old django website and want to migrate these users to drupal-7. Please suggest some tricks or tutorial. I googled a lot but was unable to find any direct solution.
Thank you for your help and suggestions.

I believe there is not an module for this, specifically. But the migrate module can help you with the migration. It demands that you create some code for the migration. But it is necessary only if your users have a lot of custom fields.
If they are simple users (username/email/password), you only would need to make a simple script to create users. In that case, you can use the drupal_bootstrap to start it from an external script and with user_save create the users.
<?php
define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_boostrap(DRUPAL_BOOTSTRAP_FULL);
//set up the user fields
$fields = array(
'name' => 'user_name',
'mail' => 'user_name#example.com',
'pass' => $password,
'status' => 1,
'init' => 'email address',
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
),
);
//the first parameter is left blank so a new user is created
$account = user_save('', $fields);

Related

Prestashop quantities update through webservice

I'm building an API for a prestashop Website. I want to update my products from an external source
So i do a PUT Request on the product's stock_availables and that's fine as far as backoffice is concerned.
Although when i make a GET Request i get quantity=0
Any idea why?
Quantity is kept in stock_availables. You can try:
$xml = $webService->get([
'resource' => 'stock_availables',
'id' => $id,
]);
$quantity = $xml->stock_available->quantity;

AWS Connect : How do I show company name on outbound calls instead of a phone number , or maybe both?

I have been trying to show up the company name instead of a phone number when an outbound call is initiated automatically at certain times using aws connect contact flow. So far, everything is working as it should be except for showing up the name of the company. I have been trying to find a solution or a documentation on how to show the company name instead of a number but so far could not find anything useful. the only hint I got from aws documentation was , I should set the caller id and name by myself, and no further instruction or hints on how to do it. I Tried to change the phone number using outboundcall api's contact attributes but nothing was showing up.
$result = $client->startOutboundVoiceContact([
'Attributes' => array(
'sourcePhoneNumber' => $d->company_name,
'd`enter code here`ate'=> $d->date,
'time' => $d->time,
'clinic' => $d->company_branch_name,
'address' => $d->company_branch_address,
),
'ContactFlowId' => $this->contactFlowId, // REQUIRED
'DestinationPhoneNumber' => $d->phone_number, // REQUIRED
'InstanceId' => $this->instanceId, // REQUIRED
'SourcePhoneNumber' => $this->sourcePhoneNumber,
]);
'''
where $d is my database and i am getting all the information from there
any recommendation or solution would be very much helpful. thank you.
If I recall correctly this feature is only possible in the US.

Facebook API - App using Oauth to update status of page

I have built an app using the PHP Facebook SDK. It allows users to authenticate my app with facebook OAth so that they can update their status' via my App. This works great, however a lot of my users have business pages and they want to update the status on their business page not their main personal feed. How is this possible? Below is what I have so far.
if ($status != ''){
try {
$parameters = array(
'message' => "$status"/*,
'picture' => $_POST['picture'],
'link' => $_POST['link'],
'name' => $_POST['name'],
'caption' => $_POST['caption'],
'description' => $_POST['description']*/
);
//add the access token to it
$parameters['access_token'] = $access_token;
//build and call our Graph API request
$newpost = $facebook->api(
'/me/feed',
'POST',
$parameters
);
$success['status'] = "$xml->status";
$xml2 = new XMLGenerator($success, 'facebook','status');
$returnData = $xml2->output;
$returnData = APIResponse::successResponse('200', "$xml->status");
} catch (Exception $e) {
$returnData = APIResponse::errorResponse('400', 'Facebook Error: '.$e);
}
I assume I would have to change '/me/feed'? but to what? What is they have multiple pages how would my app know which page to post to?
Any help with this would be much appreciated.
You can substitute me with the PAGE_ID to post to a page e.g., /013857894/feed. Make sure that you have completed the OAuth process with the manage_pages and publish_stream permissions. You can learn more at the link below:
https://developers.facebook.com/docs/reference/api/page/#statuses
If the user has multiple Pages then you will first need to give them some way of selecting which page they want to post to. You can find out which Facebook Pages a given user is the administrator of by calling /me/accounts for that user. You can find out more about this approach in the Connections section of this page:
https://developers.facebook.com/docs/reference/api/user/

How to use CUSTOM privacy setting for facebook post from an app in php

In PHP with facebook SDK, when I post from my app using /me/feed, if I use 'SELF' for privacy setting, it works fine. When I change it to CUSTOM with a list of ids to restrict to, I get an error for "friends" was not recognized. What does this mean?
// Works
$privacy = array(
'value' => 'SELF',
);
// Doesn't work and says 'Friends was not recognized'
$privacy = array(
'value' => 'CUSTOM',
'allow' => '{<id1>}'
}
I read through many questions on this topic before asking this one.
Also, this documentation from FB is confusing me as to what is and is not possible for an post from an app.
"Note: The privacy parameter only applies for posts to the user's own timeline and is ultimately governed by the privacy ceiling a user has configured for an app. It does not apply to posts made by an app on behalf of a user to another user's timelines or to Pages, events, or groups. In those cases, such posts are viewable by anyone who can see the timeline or content in the group or event."
you need to add a parameter called 'friends' with the value of 'SOME_FRIENDS'.
like this:
$privacy = array(
'value' => 'CUSTOM',
'friends' => 'SOME_FRIENDS',
'allow' => 'id1,id2,id3'
);

How can I retrieve a user using a query string from drupal using REST?

What I'd like
I want to be able to reset a users password without emailing them. I also need to do this via REST (it's for a kiosk system).
So I need to:
Get user with a specific username
Reset the password of that user
Try as I might, I can't get the user with a username.
The problem
After I've logged in using the admin user via REST I do:
GET on http://mydomain.com/rest/user?name=user.
According to REST documentation, this should get the user with name user.
I get a 200 response, but nothing is returned in the body.
What I've Tried
Get node from ID
Once I've logged in as admin, I can do:
GET on http://mydomain.com/rest/user/1
This works, returning the details of user 1 in the response. But I need to search for a user by username.
Different GETs
GET on http://mydomain.com/rest/user/admin
GET on http://mydomain.com/rest/user/account/name/admin
GET on http://mydomain.com/rest/user?account[name]=admin
GET on http://mydomain.com/rest/user?uid=1
GET on http://mydomain.com/rest/user/retrieve?uid=1
GET on http://mydomain.com/rest/user?account[uid]=1
All these fail.
Nodes instead of users
GET on http://mydomain.com/rest/node/1 works, but http://mydomain.com/rest/node?nid=1 gives me a 200 response with nothing in the body.
List of all users
GET on http://mydomain.com/rest/user/ doesn't show a list of all users either. I get a 200 with empty body again.
Further Details
I'm working with a Drupal 6.22 install.
I've installed the services module (3.0 RC1) and REST Server (2.0 beta 1).
I've got the session authentication module installed.
I've tried the above with the session authentication switched on and with it off.
I've enabled all node resources and user resources for the REST endpoint I've set up.
I've tried the above with and without clean URLs and nothing seems to make a difference.
Question
How do I get a user with a specific username? What am I doing wrong?
Update
I've uninstalled then reinstalled Services module, I've done the same with the REST server. I've also rolled back my version of CTools to the latest recommended one. I've added a brand new service in case it was corrupted. Nothing I do works. Frustrating!
Update 2
I've found the problem, but would like a more permanent solution. It turns out it was an error because of table naming. See my current accepted answer.
Im sorry this is so frustrating for you. Im the maintainer for services module and were really working on the documentation but I thought I would answer here to just get you moving along.
The reason you are not getting any of the data you want is because the parameters you are passing are wrong.
If you look at user_resource.inc index is defined as follows
'index' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/user_resource'),
'callback' => '_user_resource_index',
'args' => array(
array(
'name' => 'page',
'optional' => TRUE,
'type' => 'int',
'description' => 'The zero-based index of the page to get, defaults to 0.',
'default value' => 0,
'source' => array('param' => 'page'),
),
array(
'name' => 'fields',
'optional' => TRUE,
'type' => 'string',
'description' => 'The fields to get.',
'default value' => '*',
'source' => array('param' => 'fields'),
),
array(
'name' => 'parameters',
'optional' => TRUE,
'type' => 'array',
'description' => 'Parameters',
'default value' => array(),
'source' => array('param' => 'parameters'),
),
),
'access arguments' => array('access user profiles'),
'access arguments append' => FALSE,
),
Notice the third argument, parameters.
You can do all sorts of fun stuff with the index query as long as it is turned on, but what you havnt tried is ?parameters[name]=user Example below
When I make a request to http://test/api/user?parameters[name]=gdsfgsdfgsdfg&fields=name,uid
I get returned
[
{
"name":"gdsfgsdfgsdfg",
"uid":"36",
"uri":"http:\/\/test\/api\/user\/36"
}
]
Notice i also added some fields, uid and name. Obviously these are optional but it shows you the power of the index query. The same applies to nodes.
I hope this helps.
Try something like:
GET on http://mydomain.com/rest/user?parameters[name]=admin
This worked for me in Drupal7. Not sure if it'll be the same for 6. But I also had no issues with getting the index of all users using GET on http://mydomain.com/rest/user/
I found the issue. It's an error/bug with the Services module in the setup I have.
From the services.module file
449 // Now implode that array into an actual WHERE clause.
450 $where = !empty($where) ? ' WHERE '. implode(' AND ', $where) : '';
451 // Run through db_rewrite_sql to make sure proper access checks are applied.
// **** Error logged for this next line ****
452 $sql = "SELECT $fields FROM {$table} $where ORDER BY $order"; // <-- Error was logged for this line
453 $sql = db_rewrite_sql($sql);
454 $result = db_query_range($sql, $parameters, $page * 20, 20);
455 return $result;
The error
Table '<REDACTED>_drup1.users' doesn't exist query: SELECT * FROM users ORDER BY created DESC LIMIT 0, 20 in /<REDACTED>/sites/all/modules/services/services.module on line 455.
The users table in my installation is called drup_users. When I change line 452 to
452 $sql = "SELECT $fields FROM drup_{$table} $where ORDER BY $order";
It works. I'd be interested in knowing how I can have a more permanent solution. I ran update.php several times and it didn't fix this.