Author Archives: amc

Yii captcha fails mid-action

As the title suggests, along Sitecore I’ve done some Yii (PHP) development lately.

On one of these Yii projects I noticed a rather strange behavior with the default captcha action. The weirdness is related to a registration form, a standard registration form where a controller is validating and saving an AR model, nothing fancy. Here’s some pseudo:

if($model->validate())
{
    $model->verifyPassword=$model->password=Bcrypt->password_hash($model->password);
    $model->status=User::STATUS_NOTACTIVE;
    $model->randomizeActivationKey();
    if ($model->save())
    {
        etc...
    }
}

Right, so from time to time I get a client-side error saying the captcha text is incorrect, when I know for a fact it’s not. Additionally, and this is what caught my eye, I also get the hashed password appearing in the password field. Instead of 8 dots, I see 60. This led me to believe that the save() method is the one setting the error, and of course that’s what’s actually happening. I knew that save() will call validate() but I did not know that captcha gets refreshed on validate() after a number of calls, three as is the default.
Continue reading

Bind data to your site configuration in Sitecore

Whenever I have a Sitecore website that defines multiple site instances I find I will at some point have to define data specific to each of those instances.

Site instances are defined in the config file under the <sites> node. They define some default parameters (virtualFolder or hostName for instance), all of which are described in the configuration file so I won’t go into any detail about them. I do want however to reference three of them, specifically, name, language and startItem. These three because they are most commonly used to bind data to a site instance as far as I’ve seen.

The problem with any of these three is that I would have to match them one by one to some other reference. I Would have to loop through all site instances and check the parameter against that reference until I find what I am looking for. Say for instance, I have a couple of items defined in Sitecore that represent countries and there is a 1 to 1 mapping between country and sites, but these countries are defined as content items (not underneath the home root item of a site). How would I then map the country to the site? There are a lot of options here but I think none better than doing something like this:
Continue reading

Clean xslt loops with Sitecore and .net

The second time I found myself in this position, I felt I couldn’t get away with it again. Not because of anyone else, simply because it felt wrong. There’s a very low chance this is your second read-through (it’s not old code you wrote), so you probably don’t know what I’m talking about. Please bear with me for a moment as I get to the point.

What happened is that I had to build something similar to something else I build (a bit too quickly) a few weeks before, and of course I went back to take a look in the code. What I noticed was that I found it hard to read, and hard to understand what was supposed to happen when all the code had run. I won’t post all the code here, primarily because I don’t have it anymore but I’ll do my best to reconstruct the part I actually wanted to talk about.
Continue reading

Unique global settings object in Sitecore

Most Sitecore solutions have a settings item defined somewhere in the database. They also have settings defined in configuration files (application settings), and although they’re two different types of settings, I never found it necessary to keep them separate. On the contrary, I find applications are much more maintainable if the two were defined together.

My content and client admins would not and could not define settings on their own, so there is no chance of overriding a setting’s value. But I’m getting ahead of myself, as this phrase might not make a lot of sense without seeing some code first, so here it is.

The main idea is to create a class model of my settings item. When the settings item defines CurrencyPrefix and CurrencySuffix, the class model would look like this.
Continue reading

Exposing .net object to xslt file in Sitecore

I’ve used this solution a long time now, it works great. The main idea is to provide the same object to not only my .net classes but also my xslt files. The first time I found myself in this position, I was looking for a way to pass application settings to my xslts without having to read the same sitecore item more than once per request.
Continue reading

Send non-campaign emails with sitecore ECM

How do I send non-campaign emails with sitecore’s ECM ?! That would be so cool! Hold on… the ECM is used for campaigns, for newsletter sending, for sending emails to multiple users. I should use a different email server for every-day emails… Yeah, then I’ll just check on this for fun I guess…

For sending campaign emails, Sitecore ECM makes use of two pipelines: DispatchNewsletter and SendEmail.

I am not interested in the first one, just by its name I think I can safely assume it’s irrelevant to what I’m trying to do, I don’t have a newsletter.

Going forward, it looks like SendEmail consists of two processors: FillEmail and SendEmail. After some mild testing and debugging, I’m pretty sure FillEmail will replace email tokens and SendEmail will use SendingManager to send the email.

Sitecore.Modules.EmailCampaign.SendingManager looks to already offer a couple of methods for sending emails.

SendingManager.SendMessage(), will pass through the DispatchNewsletter pipeline and that doesn’t help me because that will try to send the email through the same process as sending a newsletter. Hence, Sitecore will move my email to the processing folder.

SendingManager.SendStandardMessage(Contact), does not move the email from drafts to processing but it still calls some processors in the DispatchNewsletter pipeline. It will call DeployAnalytics, try to create Campaigns, Engagement plans, Subject MVTs. There’s a lot of overhead with SendStandardMessage so I don’t like this one either. Additionally I came across the following jewel: The UPDATE statement conflicted with the FOREIGN KEY constraint “FK_Automation_Campaign”. The conflict occurred in database “Sitecore_Analytics”, table “dbo.Campaigns”, column ‘CampaignId’..

That leaves me having to write my own.
Continue reading