MissEmmaGoodwin Command Line Addict

17Jan/126

Have you been unable to validate / submit your iphone / mac app? Nothing but errors reported with your certifcates?

I have literally spent all weekend trying to submit my client's iPhone app to the app store. I must have setup the certificates and distribution provisioning profile over 50 times, but to no success. I lost count of the amount of times I saw the following error message:

Application failed codesign verification.  The signature was invalid, or it was not signed with an iPhone Distribution Certificate. (-19011)

After visiting what felt like the thousandth forum, I shut off my laptop and resided to the fact that my only port of call left was to speak to Apple. The next morning I made the call and they were actually very efficient in dealing with my issue. Unfortuneately they could only offer me the same advice that I had found myself online.  They suggested that if their advice does not solve my problem, I would need to raise a TSI (technical support incident), which I did straight after.

I later found out that raising such request was chargeable - "A Technical Support Incident (TSI) will be debited from your developer account for this inquiry.  If it is determined that your question cannot be supported by DTS, the TSI will be credited back to your developer account. ".

Today a response was received from Apple:

 

After all that, it was a problem on there end! Most frustrating!

If you come across the same errors after you have triple checked your certificates and you are signing your app with the correct profile (distribution!) I would seriously recommend that you just call Apple. I found this page a few weeks ago and it has been really handy. It contains all the worldwide numbers for Apple Developer Support. Link: http://developer.apple.com/contact/phone.php

 

7Jan/120

No access to WordPress CMS? Have FTP login? No Problem!

I was tasked with changing some details on a WordPress site. I only had FTP details and everything that needed to be changed involved logging in with a user which had Administrator privileges. Some of the changes were bug fixes and time was of the essence.

What I am about to show you is very much a 'dirty workaround'; there are much better ways of doing it (either programmatically in the code or even just asking for the admin password). But if you are on a very tight deadline, this will most certainly help you.

 

Creating a Super Admin user programmatically

Connect via FTP. Open up any .php file that gets called. I used wp-content/themes/active-custom-theme/header.php.
 
1. Create the user

/*******************************************************************************
* If ?adduser=true is set in URL, the following code will be executed.
* This ensures that only YOU see the code that is output from the php
********************************************************************************/
if($_GET['adduser'] == 'true') {

     /*************************************************************************
     * Create user
     **************************************************************************/
     wp_create_user('tmproot', '3029332', 'you@yourmailbox.com');

     /*************************************************************************
     * Print out a list of all users
     **************************************************************************/
     $result = mysql_query("SELECT * FROM wp_users");
     while($objResult = mysql_fetch_object($result)) {
          echo '<pre>' . print_r($objResult,1) . '</pre>';
     }
}

 

2. Retrieve the your user's ID
Go to wordpress-site.co.uk/?adduser=true and make a note of the ID of the user you just added.

 
3. Retrieve the serialized array of permissions for the Super Admin
Go back to your file and change the PHP to the following:

/*******************************************************************************
* If ?adduser=true is set in URL, the following code will be executed.
* This ensures that only YOU see the code that is output from the php
********************************************************************************/
if($_GET['adduser'] == 'true') {

     /*************************************************************************
     * Create user
     **************************************************************************/
     //wp_create_user('tmproot', '3029332', 'you@yourmailbox.com');

     /*************************************************************************
     * Print out a list of all users
     **************************************************************************/
     //$result = mysql_query("SELECT * FROM wp_users");
     //while($objResult = mysql_fetch_object($result)) {
          //echo '<pre>' . print_r($objResult,1) . '</pre>';
     //} 

     /*************************************************************************
     * Print out all the permissions
     **************************************************************************/
     $result = mysql_query("SELECT * FROM wp_usermeta");
     while($objResult = mysql_fetch_object($result)) {
          echo '<pre>' . print_r($objResult,1) . '</pre>';
     }
}

Save the file and refresh wordpress-site.co.uk/?adduser=true. Copy the value meta_value for ID 1 and make a note of your user's umeta_id.
 
4. Update your user's permissions
Go back to your file and change the code to the following:

/*******************************************************************************
* If ?adduser=true is set in URL, the following code will be executed.
* This ensures that only YOU see the code that is output from the php
********************************************************************************/
if($_GET['adduser'] == 'true') {

     /*************************************************************************
     * Create user
     **************************************************************************/
     //wp_create_user('tmproot', '3029332', 'you@yourmailbox.com');

     /*************************************************************************
     * Print out a list of all users
     **************************************************************************/
     //$result = mysql_query("SELECT * FROM wp_users");
     //while($objResult = mysql_fetch_object($result)) {
          //echo '<pre>' . print_r($objResult,1) . '</pre>';
     //} 

     /*************************************************************************
     * Print out all the permissions
     **************************************************************************/
     //$result = mysql_query("SELECT * FROM wp_usermeta");
     //while($objResult = mysql_fetch_object($result)) {
          //echo '<pre>' . print_r($objResult,1) . '</pre>';
     //} 

     /*************************************************************************
     * Update your user's privileges
     * There are a few other ways to do this. I tried $user->set_role($role)
     * but this didn't work for me. The following code did work:
     **************************************************************************/
     $perms = 'a:1:{s:13:"administrator";s:1:"1";}';
     $umeta_id = 101;
     $sql = "UPDATE wp_usermeta SET meta_value = '".$perms."' WHERE umeta_id = " . $umeta_id;
     mysql_query($sql);

}

Now go to wordpress-site.co.uk/wp-admin and login with your new user. Make all the changes you need to make.

5. Cleanup
Go back to the code and add the following to delete the user you created:

/*******************************************************************************
* If ?adduser=true is set in URL, the following code will be executed.
* This ensures that only YOU see the code that is output from the php
********************************************************************************/
if($_GET['adduser'] == 'true') {

     /*************************************************************************
     * Create user
     **************************************************************************/
     //wp_create_user('tmproot', '3029332', 'you@yourmailbox.com');

     /*************************************************************************
     * Print out a list of all users
     **************************************************************************/
     //$result = mysql_query("SELECT * FROM wp_users");
     //while($objResult = mysql_fetch_object($result)) {
          //echo '<pre>' . print_r($objResult,1) . '</pre>';
     //} 

     /*************************************************************************
     * Print out all the permissions
     **************************************************************************/
     //$result = mysql_query("SELECT * FROM wp_usermeta");
     //while($objResult = mysql_fetch_object($result)) {
          //echo '<pre>' . print_r($objResult,1) . '</pre>';
     //} 

     /*************************************************************************
     * Update your user's privileges
     * There are a few other ways to do this. I tried $user->set_role($role)
     * but this didn't work for me. The following code did work:
     **************************************************************************/
     //$perms = 'a:1:{s:13:"administrator";s:1:"1";}';
     //$umeta_id = 101;
     //$sql = "UPDATE wp_usermeta SET meta_value = '".$perms."' WHERE umeta_id = " . $umeta_id;
     //mysql_query($sql);

     /*************************************************************************
     * Delete the new user you just created
     **************************************************************************/
     $sql = "DELETE FROM wp_users WHERE ID = 10001";
     mysql_query($sql);

}

Refresh wordpress-site.co.uk/?adduser=true which will delete the user you created. Then go back to your php file and delete all the code you added.

3Jan/122

SVN Revert – how to roll back (revert) code to a previous version

Up until a few months ago, I never needed to roll back any code that I have committed into a repo. However very recently, there have been several occasions where I have needed to revert my changes:

  • The project's goalposts have changed significantly, it has been quicker to just start again
  • I've committed more code than I intended to (e.g. I've released two Drupal modules and one of them was still in active development)
  • The latest code caused an issue where PHP was out of date on the client's server

Unfortunately using subversion, there is no straight forward way to roll back your code  You have to merge your local checkout with a previous version and then commit the changes.

Executing the following commands will enable you to revert your changes back to a previous version:

svn merge --dry-run -rHEAD:80 https://your-svn.com/client/site/trunk
See what files will be be reverted

svn diff -rHEAD:80 https://your-svn.com/client/site/trunk
View the code changes that will be applied in the roll back

svn merge  -rHEAD:80 https://your-svn.com/client/site/trunk
Merge the current version to revision number 80

svn ci -m 'Repo rolled back to revision 80'
Commit your changes back into the repo to complete the roll back

The first two commands can be omitted, no changes are made.  When I commit after a merge, I normally use the previous command as my commit message. It is useful when reviewing the SVN logs:

svn ci -m 'svn merge  -rHEAD:80 https://your-svn.com/client/site/trunk'

 

Tagged as: 2 Comments
21Dec/117

Using Features in Drupal 7

For some time managing Drupal database changes between development, staging and live server environments has been tricky. Normally to ensure that no database changes are lost I create the database changes on the staging site, dump the database and import them into my development environment.

Today I have just discovered the wonderful world of Features! This module basically enables you to package your database changes as a 'feature' (which essentially is just a module) which you can then deploy and install to other Drupal builds.

Using this module I was able to package my newly created content type and associated views. Then I was able to deploy this 'feature' to ten different website on a Multi-site setup. Replicating these changes manually on each site would have taken me well over an hour. Using the Features module, this task took me less than 10 minutes!

 

Creating and deploying a Feature (using Drush)

Create all your different content types, views and menus etc as you would normally.

drush dl features
Download the features module to your modules directory. This will either be sites/default/modules or sites/site-name.co.uk/modules for Drupal Multi-sites.

drush en features
Enable the features module.

Navigate to yoursite.co.uk/admin/structure/features/create to create a Feature. Give your feature a name, meaningful description and a version number: 

Creating Features in Drupal 7

 

Select all the components you wish to package in this feature:

Using Features in Drupal 7

Once you have selected all your components, click "Download feature". This will create all the module files and download them to your local machine. SCP / FTP these files to your other Drupal site, enable the module and bobs your uncle.

 

Edit: For some unknown reason, when enabling the feature using drush, some of the form fields on the custom content type do not pull through. If you have this problem, disable then re-enable the module using the Drupal frontend. This resolved the problem for me.

 

21Dec/116

Editing multiple files with vim

There have been many occasions when I have been working on a Drupal Multi-site setup where it has been necessary to modify the JavaScript or CSS stylesheet for each site.

Normally I would have a clever SVN setup in place (using svn:externals) so I can just make the changes to one file and then simply export this change to all sites. However, this is not always possible, especially when working on an existing Drupal Multi-site which has a different setup.

Thanks to this twitter post by @climagic, I worked out a way to quickly add a new CSS class to every stylesheet in a Drupal Multi-site.

Once I am in the right directory, executing the following commands enabled me to add the new class:

vim $( grep -l -r '#myuniqueid' *  | grep -v .svn )
This finds and opens every file which has "#myuniqueclass". The unique class is specified as I only want to open the main stylesheet which has all the site's styling (and not the print / ie stylesheets etc). "grep -v .svn" is added to exclude all the svn files.

i
Enter insert mode

cmd+v
Paste new CSS class

esc
Escape out of insert mode

u
Undo last change, this will be run again across all files in the next command

:argdo exe “normal G.” | w
Across all open files, go to the end of the (G), repeat the last operation (.) and save the file (w)

New CSS class added to 11 websites in less than 60 seconds 10 seconds! Credit to Dale for improving this post.

 

Additionally, the following command can be executed to search and modify all files based on the filename instead of the file's content:

vim $( find -name 'general.js' )

21Dec/110

Welcome…

Welcome to my first blog post.

Over the years I have collected snippets of code and created many mini tutorials to overcome the problems that I have come across as web developer. Up until now, they have been locked away in an Evernote database.

Over time I will share all my findings and convert the tutorials into blog posts on here. I hope you find them useful and they save you as much time as they have saved me.

 

Filed under: Misc No Comments