I am trying to compare an email address inputed from a form to what is already in the database and I figure the best way to do so is with using a findByEmail method.
I expected that to find the email address for a specific entry in the table but instead it returns the whole entry (first name, last name, and more…).
How do I only find the email address of the entry in the table?
I know I can use a foreach to iterate through the entry but I think that kinda defeats the purpose of using a findByEmail function.
Here’s what I’ve tried so far:
$formEmail = $form->get('email')->getData();
$personEmail = $em->getRepository('UserBundle:User')->findByEmail($formEmail); //Should just find the email address of a person in the database.
var_dump($personsEmail); //returns the whole row associated with the email address (first name, last name…..)
var_dump(if($formEmail == $personEmail));die; //returns false when it should be true because it finds the whole row instead of the email address
If you fetched the entity successfully by email then the email must match.
$formEmail = $form->get('email')->getData();
$person = $em->getRepository('UserBundle:User')->findOneByEmail($formEmail);
if ($person instanceof User) {
// you found a user by email, so the email therefore must match ...
}
Note, use findOneBy not findBy, then you will fetch the object directly instead of in a collection.
Alternatively if you must fetch just the email address for comparison.
$email = $em->createQueryBuilder()
->select('u.email')
->from('UserBundle:User', 'u')
->where('u.email = :email')
->setParameter('email', $formEmail)
->getQuery()
->getSingleScalarResult()
;
Note though that you could just use $person->getEmail() in my first example for the same result.
Related
The SES data type has the sesFrom field. Everywhere on the Internet I see that I should write something like "\"My Name\" <mymail#gmail.com>" in order to display My Name in the "from" field. But when I put this into the sesFrom field I get
Not sent due to SESException {seStatus = Status {statusCode = 400, statusMessage = "Bad Request"}, seCode = "InvalidParameterValue", seMessage = "Missing '<'", seRequestId = "acf8bb7d-0440-11e8-94c8-45570c829243"}
I checked sources and all seems to be fine there. How do I set the sesFrom field, so a name is displayed?
OK, got it. Instead of writing "\"My Name\" <mymail#gmail.com>" :: Address and relying on OverloadedStrings one should write
Address (Just "Ny Name") "mymail#gmail.com"
I'd say the library should parse "\"My Name\" <mymail#gmail.com>" into that address, but whatever.
Via a logic hook I'm trying to update fields of my products, after an invoice has been saved.
What I understand so far is, that I need to get the invoice related AOS_Products_Quotes and from there I could get the products, update the required fields and save the products. Does that sound about right?
The logic hook is being triggered but relationships won't load.
function decrement_stocks ( $bean, $event, $arguments) {
//$bean->product_value_c = $bean->$product_unit_price * $bean->product_qty;
$file = 'custom/modules/AOS_Invoices/decrement.txt';
// Get the Invoice ID:
$sInvoiceID = $bean->id;
$oInvoice = new AOS_Invoices();
$oInvoice->retrieve($sInvoiceID);
$oInvoice->load_relationship('aos_invoices_aos_product_quotes');
$aProductQuotes = $oInvoice->aos_invoices_aos_product_quotes->getBeans();
/*
$aLineItemslist = array();
foreach ($oInvoice->aos_invoices_aos_product_quotes->getBeans() as $lineitem) {
$aLineItemslist[$lineitem->id] = $lineitem;
}
*/
$sBean = var_export($bean, true);
$sInvoice = var_export($oInvoice, true);
$sProductQuotes = var_export($aProductQuotes, true);
$current = $sProductQuotes . "\n\n\n------\n\n\n" . $sInvoice . "\n\n\n------\n\n\n" . $sBean;
file_put_contents($file, $current);
}
The invoice is being retrieved just fine. But either load_relationship isn't doing anything ($sInvoice isn't changing with or without it) and $aProductQuotes is Null.
I'm working on SuiteCRM 7.8.3 and tried it on 7.9.1 as well without success. What am I doing wrong?
I'm not familiar with SuiteCRM specifics, however I'd always suggest to check:
Return value of retrieve(): bean or null?
If null, then no bean with the given ID was found.
In such case $oInvoice would stay empty (Your comment suggests that's not the case here though)
Return value of load_relationship(): true (success) or false (failure, check logs)
And I do wonder, why don't you use $bean?
Instead you seem to receive another copy/reference of $bean (and calling it $oInvoice)? Why?
Or did you mean to receive a different type bean that is somehow connected to $bean?
Then its surely doesn't have the same id as $bean, unless you specifically coded it that way.
I have a script behind a Google spreadsheet that sends an email once certain cells of a row is completed. The script works by sending to multiple hard coded email addresses. How can I add the current user's email address as a 2nd CC? One of the CC is hard coded but the 2nd changes depending on the person updating the spreadsheet. I know how to grab the email address but how do I pass it as a variable so it actually gets CC-ed?
var currentemail = Session.getActiveUser().getEmail();
var options = {cc: 'Session.getActiveUser().getEmail(), someotheremail#domain.com'};
or
var options = {cc: 'currentemail, someotheremail#domain.com'};
GmailApp.sendEmail(email, subject, body, options);
Obviously these do not work :)
Many thanks in advance
this can be done like below :
function sendWithCc(){
var currentemail = Session.getActiveUser().getEmail();
var options = {};// create object
options['cc'] = currentemail+',someotheremail#domain.com';// add key & values (comma separated in a string)
GmailApp.sendEmail('somemail#domain.com', 'subject', 'body', options);
// I stringified 'subject' and 'body' to make that test work without defining values for it
}
Your examples should be modified as follows:
var options = {cc: Session.getActiveUser().getEmail()+', someotheremail#domain.com'};
Or
var options = {cc: currentemail+', someotheremail#domain.com'};
You cannot call a function, or reference a variable, from within a string. Instead, use the + operator to join the value of your variable (or the return value of your function call) with the string.
Note, depending on the context in which this code will be used, the script may not have permission to access the users identity regardless. See the notes under GetActiveUser() here: https://developers.google.com/apps-script/reference/base/session#getActiveUser()
I have large list of email addressses from a file. It comes around 1 million email ids. I have list of bad words like spam,junk etc, it consist of 20,000+ bad words.
I need to validate email ids. If bad words is present any where in email id it will be marked as invalid.
For example;
testspam#gmail.com - invalid
newuser#desspam.com - invalid
I would like to know which will be fastest comparison method as array looping will take time.
I tried following methods
//$keyword_list- array of bad words;
//$check_key- the email id which need to validate
$arrays = array_chunk($keyword_list, 2000);
for($i=0;$i<count($arrays);$i++)
{
if (preg_match('/'.implode('|', $arrays[$i]).'/', $check_key, $matches)){
return 1;
}
}
The above method is taking more time when comparing 1 million data.
Next we tried with the following code and this also takes more time
//$contain = bad words separated by '|'
// $str - the email id which need to validate
if(stripos($contain,"|") !== false)
{
$s = preg_split('/[|]+/i',$contain);
$len = sizeof($s);
for($i=0;$i < $len;$i++)
{
if(stripos($str,$s[$i]) !== false)
{
return(true);
}
}
}
if(stripos($str,$contain) !== false)
{
return(true);
}
return(false);
Finally I had tried Mongodb Text Search. It works fast with the following issues
If 'Hell' is the word in my bad list and my email id is like
head#e-hellinglysussex.sch.uk, then the Mongodb Text Search wont matches it.
Here is the code I used;
$ret = $db->command( array("text" =>$section, "search" => $keyword_string, "limit"=>$cnt_finalnonmatch));
where $section = Collection name,
$keyword_string = Comparing keywords string separated by space, for eg "Hell Spam Junk" etc,
$cnt_finalnonmatch = total number of comparing email ids
Please help me to solve this issue.
I am not entirely sure, but I suspect that the problem is that 'Hell' is not equal to 'hell' when you search for text since mongodb is case sensitive.
The solution should be to force all the strings and word to be lowercase (or uppercase)
We have used Mongodb 'like' to solve this issue;
$keywords = $key['keyword']; // Keywords need to compare
$regexObj = new MongoRegex("/".$keywords."/i"); // MongoRegex function declration
$where = array($section => $regexObj); // $section is the collection name
$resultset = $info->find($where);
I am trying to resolve name using ExchangeService::ResolveName API
But problem is the Contact ItemId is always null, though there is a match
NameResolutionCollection matchingnames = service.ResolveName("X#X.com", ResolveNameSearchLocation.DirectoryOnly, true);
foreach (NameResolution item in matchingnames)
{
Contact contact = item.Contact;
contact.ItemId // This is always NULL irrespective
}
Am I doing something wrong
How can I dig-down the contact details..like profile picture I can't do it as ItemId for contact is NULL always
I also observed on my environment that "contact" is always set to "null" for each NameResolutionCollection item, but the Mailbox property is filled.
So you can try this:
EmailAddress address = item.Mailbox;
String Name = address.Name.ToString();
I think you have to include the PropertySet argument to include first-class properties,
outlined here... More information about PropertySet.
NameResolutionCollection matchingnames = service.ResolveName("X#X.com", ResolveNameSearchLocation.DirectoryOnly, true, PropertySet.FirstClassProperties);