Google Directory API - batch add members to a group - google-admin-sdk

I am using the Google Admin SDK to create, update and delete mailing lists (aka groups).
Everything works fine so far and I can create a new group and add members to it. But: Every adding of a member takes about 1s so I was thinking of a batch request to add several users to a group at once.
In the Google Admin interface it is easy to add several users at once but I didn't find any way to implement this via the API.
Is there a way to do so or do I have to loop through every user?
This works but takes a lot of time if I have to do it for every single user:
$service = new Google_Service_Directory($this->getGoogleClient());
$user = new Google_Service_Directory_Member();
$user->setEmail('test#test.com');
$user->setRole('MEMBER');
$user->setType('USER');
$service->members->insert($group_id, $user);

finally I found a solution on my own: The Admin SDK comes with a Batch class :)
To get batch requests working these steps are necessary:
When initiating the Google Client add the following line to the code
$client->setUseBatch(true);
then you can initiate the batch object
$batch = new Google_Http_Batch($client);
a little modification on the code posted above brings me to this code
foreach($arr_users as $user)
{
$userdata = new Google_Service_Directory_Member();
$userdata->setEmail($user);
$userdata->setRole('MEMBER');
$userdata->setType('USER');
$batch->add($service->members->insert($temp_list_name, $userdata));
}
finally you have to execute the request which is done by this line:
$client->execute($batch);
that's all and it works perfectly

While using the method of Christian Lange I was getting this error -
Argument 1 passed to Google\Client::execute() must implement interface Psr\Http\Message\RequestInterface, instance of Google\Http\Batch given,
So I used this instead
$client->setUseBatch(true);
$service = new Google_Service_Directory($client);
$batch = $service->createBatch();
foreach ($emails as $email)
{
$user = new Google_Service_Directory_Member(array('email' => $email,
'kind' => 'member',
'role' => 'MEMBER',
'type' => 'USER'));
$list = $service->members->insert($key, $user);
$batch->add($list);
}
$resultsBatch = $batch->execute();

Related

Get name of next doctrine migration

How could I get the name / version of the next migration to execute? Something similar to migrations:latest but more like migrations:next. I need this as input to another command so it needs to be parseable output (can't really just use migrations:status).
You can use the Configuration object of the Doctrine migrations bundle. This is even (somewhat) documented as custom configuration.
Here is a minimal code example that works for me:
public function migrationVersionAction(EntityManagerInterface $em, ParameterBagInterface $parameters) {
$connection = $em->getConnection();
$configuration = new \Doctrine\Migrations\Configuration\Configuration($connection);
$configuration->setMigrationsNamespace($parameters->get('doctrine_migrations.namespace'));
$configuration->setMigrationsDirectory($parameters->get('doctrine_migrations.dir_name'));
$configuration->setMigrationsTableName($parameters->get('doctrine_migrations.table_name'));
return new JsonResponse([
'prev' => $configuration->resolveVersionAlias('prev'),
'current' => $configuration->resolveVersionAlias('current'),
'next' => $configuration->resolveVersionAlias('next'),
'latest' => $configuration->resolveVersionAlias('latest')
]);
}
You might want to set the remaining parameters as well though, especially if they differ from the defaults. For this, the configuration documentation might help in addition to the link above.

How to add a combo drop-down user list in vtigercrm?

I'm using existing Task module under the Project module. I would like to
assign particular task to multiple workers. Meaning that group of people
will together complete the task.
I already have workers as users in my vtigercrm. So if i make a user selection
multiple for assigning single task it could be easier to handle this
use-case.
This use-case already have in Calendar module but i'm unable to understand how they implement.
I have a thorough knowledge on how to create custom user list drop-down in any module and i created lot more for my custom modules. Now stuck with the same scenario having multiple at a time.
I tried like this in module.php, but it is not working.
$users = Vtiger_Module::getInstance('Users');
$module = Vtiger_Module::getInstance('MyModule');
$module->unsetRelatedList($users, 'Users', 'get_related_list');
$module->setRelatedList($users, 'Users', array('SELECT'), 'get_related_list');
Can anyone help me to get it done?
It is possible when you understood the Invite users field in Calender envent creation. Here the field must be multi-selection.
You need to deal with vtiger_salesmanactivityrel table for inserting the multiple users and for showing in detail view.
Here is the code to handle inviteusers.
//Handling for invitees
$selected_users_string = $_REQUEST['inviteesid'];
$invitees_array = explode(';',$selected_users_string);
$this->insertIntoInviteeTable($module,$invitees_array);
function insertIntoInviteeTable($module,$invitees_array)
{
global $log,$adb;
$log->debug("Entering insertIntoInviteeTable(".$module.",".$invitees_array.") method ...");
if($this->mode == 'edit'){
$sql = "delete from vtiger_invitees where activityid=?";
$adb->pquery($sql, array($this->id));
}
foreach($invitees_array as $inviteeid)
{
if($inviteeid != '')
{
$query="insert into vtiger_invitees values(?,?)";
$adb->pquery($query, array($this->id, $inviteeid));
}
}
$log->debug("Exiting insertIntoInviteeTable method ...");
}
Hope it would give you a better idea.

Nested pagination in facebook graph api while using php-sdk-v4

I am trying to get all users who likes a specific post on a feed. I am using facebook/php-sdk-v4 . There is no problem on getting next page for feed. However when I use next function to get next users who liked that post in inner loop it gives
Error:Caused by: Facebook\Exceptions\FacebookAuthenticationException
Subfields are not supported by feed.
In FacebookRequest.php I disabled appsecret_proof, maybe it is related to this security issue. If I don't disable, it gives now invalid appsecret_proof despite v5.0 sdk already generates appsecret_proof internally at the line 70 of Facebook\Authentication\AccessToken.php.
Without appsecret_proof I am able to request but in some cases like batch query or loops I think there is a need for appsecret_proof. However, it generates that code itself and it gives invalid error. I don't know what to do.
$fb = new Facebook\Facebook([
'app_id' => '60...
]);
$feed = $graphNode->getField('feed')
while(true) {
foreach ($feed->all() as $key1 => $post) {
if ($likes = $post->getField('likes')){
while(true) {
if (!($likes = $fb->next($likes))) break;
}
}
}
if (!($feed = $fb->next($feed))) break;
}

how would you use subscription managers with meteor's template subscriptions?

Meteor recently introduced template subscription capabilities. You can now call this.subscribe from within a Temeplate.xyz.onCreated call and the helper {{#if Template.subscriptionsReady}} will only be true once the subscriptions have gotten ready from the server.
Unfortunately this does not seem to be obviously compatible with subs-manager or subs-Cache
How woudl you use subs-Cache in-place of this.subscribe such that the subscription ids made by the subsciptions manager make it into _subscriptionHandles and _allSubsReady part of this.subscribe? Or otherwise asked, how do you get {{#if Template.subscriptionsReady}} and the function Template.instance().subscriptionsReady() to depend on Template subscriptions made with subs-Cache.
Example code that does not work:
# in some top level file
share.subsCache = new SubsCache(
expireAter: 5
cacheLimit: 10
)
#in a template file
Template.entryRevisionInfo.onCreated ->
share.subsCache.subscribe('somePub')
The next (unreleased) version of meteor has a connection option to TemplateInstance#subscribe, and I would expect that you would be able to pass a subscription manager as the "connection."
Sacha Greif wrote a solution in the Telescope app. I've tried to extract the parts that are significant to a basic implementation below. As far as I understand it relies on explicitly setting the ready status of the template... setting it reactively when the subscription is ready:
subsManager = new SubsManager();
Template.templatename.onCreated(function () {
var instance = this;
instance.ready = new ReactiveVar(false);
subscription = subsManager.subscribe('yourCollection')
instance.autorun(function () {
if (subscription.ready()) { //reactive
instance.ready.set(true);
}
}
}

acknowledge order report amazon mws

I am using "GetReportList" api with report list type as "_GET_ORDERS_DATA" to pull order reports from amazon. But I want to pull only new orders. How can I use the "acknowledged" field to make sure that I pull only new orders(which were not previously pulled).I observed that the "acknowledged" field is true by default. Please let me know if there is a way to pull new orders only(I am trying to avoid using timestamp here)
Thanks
You need to acknowledge the order report when you picked it up, then you will only get order reports set to acknowledged false on the next call.
So you need to run this operation:
$request1 = new MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest();
$request1->setMerchant(MERCHANT_ID);
$idList1 = new MarketplaceWebService_Model_IdList();
$request1->setReportIdList($idList1->withId(/* SET THE REPORT ID YOU HAVE TAKEN */));
$request1->setAcknowledged(true);
invokeUpdateReportAcknowledgements($service, $request1);
function invokeUpdateReportAcknowledgements(MarketplaceWebService_Interface $service, $request1)
{
try {
$response = $service->updateReportAcknowledgements($request1);
} catch (MarketplaceWebService_Exception $ex) {
var_dump($ex);
After you have picked up the order report, and then, you can simply request the next order report with this line:
$request->setAcknowledged(false);
Like this, only reports you haven't set to acknowledged with the first call will be shown in the list.
The first call is described in the php API, I think it's called something like SetAcknowledgmentSample, and the second call needs to be called in the getReportListSample file
I think you can set them as below which I found from sample code found in Amazon Report's API sample
$parameters = array (
'Merchant' => MERCHANT_ID,
'AvailableToDate' => new DateTime('now', new DateTimeZone('UTC')),
'AvailableFromDate' => new DateTime('-6 months', new DateTimeZone('UTC')),
'Acknowledged' => false,
);
$request = new MarketplaceWebService_Model_GetReportListRequest($parameters);
$request = new MarketplaceWebService_Model_GetReportListRequest();
$request->setMerchant(MERCHANT_ID);
$request->setAvailableToDate(new DateTime('now', new DateTimeZone('UTC')));
$request->setAvailableFromDate(new DateTime('-3 months', new DateTimeZone('UTC')));
$request->setAcknowledged(false);