Showing posts with label Drupal. Show all posts
Showing posts with label Drupal. Show all posts

Thursday, April 21, 2016

Drupal - Field Collection - Appending/Inserting an Entity

Kudos for this solution goes to Drupaler Justin Fraser :
Slightly changed description to fit more of my append/insert issue.


I had an issue where I was trying to append new field collection entity to the 'user' Field Collection and doing so would delete any existing items. The solution was to directly load the user entity and not depend on the global $user as that one doesn't have the field collection information.
$thisUser = entity_load('user', array($user->uid));
$thisUser = $thisUser[$user->uid]; //make thisUser the user object, not an array of user objects

$newFieldCollectionItem = array();
$newFieldCollectionItem['field_name'] = 'field_download';
$newFieldCollectionItem['field_download_filename'][LANGUAGE_NONE][0]['value'] = $src;
$newFieldCollectionItem['field_download_date'][LANGUAGE_NONE][0]['value'] = time();

$newFieldCollection = entity_create('field_collection_item', $newFieldCollectionItem);
$newFieldCollection->setHostEntity('user', $thisUser);
$newFieldCollection->save();

Line 2 $thisUser[$user->uid] is what made it work for me.

The rest of the code had been the exact same, but adding line 2 is what did it for me!!!

Monday, February 27, 2012

Drupal - Bootstrap for old PHP script

In a hurry and I have an old PHP application that pulls data from proprietary tables.  I have connected some of the data to a node, but now I need to display the data in a separate window when applicable.

So, using the old and large PHP script, just to get it functioning, I had to bootstrap Drupal.
Place this at the beginning of OldLarge.php


$drupal_dir = getenv("DOCUMENT_ROOT");
$current_directory = getcwd();
chdir($drupal_dir);


require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

...
Do my Drupal stuff here....db_query() and whatever so that I can get results back from weird tables.
...

Then at the end of  OldLarge.php , add the final code....


chdir($current_directory);


Eventually...some day (which ends up being never) I will convert the OldLarge.php script to something more Drupalized.

Tuesday, December 13, 2011

CiviCRM - moving your configuration changes to a different environment

I love code driven development.  So when I build my Drupal sites, I immediately download and enable Features.  I do not want to handle website settings between environments by comparing screens and clicking box after box.  When you are running in a local DEV environment, plus you have a TEST and LIVE environment, using Features saves time (which of course equals money).

So I started a new project using CiviCRM and the thought in the back of my mind for awhile was:

"I just changed a CiviCRM setting.  How do I migrate that change to my TEST and LIVE environments?".  

Well the time came and I had to do it.  I needed to get my TEST site going and didn't want to bother remembering all of the settings I needed to configure.

Luckily, CiviCRM comes with migrate scripts to Export and Import your settings.

First Export it from the localhost (DEV environment) using one of the options.  More exist, but these are pretty basic:

  1. Browse to
    1.  http://localhost/virtual_dir/sites/all/modules/civicrm/bin/migrate/export.php?name=&pass=&key=
      1. This will download a file called CustomGroupData.xml
  2. Using wget (if you want to script this and update the file at 3pm for example)
    1. wget -O D:\dev\htdocs\virtual_dir\sites\default\CiviCRM.info "http://localhost/virtual_dir/sites/all/modules/civicrm/bin/migrate/export.php?name=&pass=&key="


I save this file to a folder in the website I am working on.  Then, if it has changed, I commit it to git.

After the export file has been committed to git, then moved to your next server, import:
http://example.com/sites/all/modules/civicrm/bin/migrate/import.php?name=&pass=&key=&file=../../../../../default/CiviCRM.info


Notice the difference between this command and previous ones is that it uses import.php and specifies a file.

I noticed there were a couple of settings that did not get exported and I think those are related to CiviCRM Profiles.  I need to look into this a bit and see if this is an issue or "works as designed".

What are some other options for moving CiviCRM configuration changes between environments?

Friday, September 2, 2011

Almost 3 Years!!!

Hey look, I've been a member of D.O for nearly 3 years now.  :)


Tuesday, June 15, 2010

Drush Make on Windows

Here is a compilation of information (from posts I've found), that when combined got me drush make to work on my windows box.  Windows 7 has some issues with permissions, but I'm looking into that.

Needed to run:

  1. Once GnuWin32 is installed, rename the copy of tar.exe to something else (tar-old.exe). Tar.exe is old and doesn't do the required things for drush_make.  There's more info on tar.exe on the GnuWin32 site (http://gnuwin32.sourceforge.net/packages/gtar.htm)
  2. Copy bsdtar.exe to tar.exe
  3. run the drush make command: drush -v -d make standard.make Test
Here is the standard.make (example):

; This file was auto-generated by drush_make
core = 6.x

projects[] = "drupal"
; Modules
projects[] = "admin_menu"
projects[] = "dhtml_menu"
projects[] = "porterstemmer"
projects[] = "token"

Wednesday, February 4, 2009

Drupal Groups

I joined the Drupal group "Iowa" to keep up-to-date with a group and to get more involved in the community. I also sent a request to create a local group in the Cedar Rapids area (Iowa-CR). Not sure what the next steps will be with that. I thought it would be cool to start a group and get together with others and brainstorm or just learn some new stuff.