<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ahmed Dirié</title>
	<atom:link href="https://ahmeddirie.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://ahmeddirie.com</link>
	<description>Ahmed Dirié is a developer who specializes in cloud based technologies, Force.com development, web application architecture, cloud server management, reporting and intelligence with OBIEE and SAP BO.</description>
	<lastBuildDate>Wed, 08 Feb 2017 21:16:02 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.25</generator>
	<item>
		<title>Migrating Drupal 7 Forums into an Adxstudio Portal in Microsoft Dynamics – Part 3</title>
		<link>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-3/</link>
		<comments>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-3/#comments</comments>
		<pubDate>Mon, 28 Sep 2015 06:13:55 +0000</pubDate>
		<dc:creator><![CDATA[ahmeddirie]]></dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Adxstudio]]></category>
		<category><![CDATA[Data Migration]]></category>
		<category><![CDATA[DCRM]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Forums]]></category>
		<category><![CDATA[Microsoft Dynamics]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ahmeddirie.com/?p=4601</guid>
		<description><![CDATA[In this final post on migrating Drupal 7 forums to an Adxstudio portal in Microsoft Dynamics, we’ll look at creating entities and workflows in DCRM to update the posts related to a thread and the total counts. This takes place with the upload of the 4th XML script we talked about in both Part 1 and Part 2. Entities Before we can create a workflow, we&#8217;ll need to create a new entity, Forum Update Thread. Click on the Customize the System link and it should open up a new window that will show you the Information and Components of your [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In this final post on migrating Drupal 7 forums to an Adxstudio portal in Microsoft Dynamics, we’ll look at creating entities and workflows in DCRM to update the posts related to a thread and the total counts. This takes place with the upload of the 4th XML script we talked about in both <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/">Part 1</a> and <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-2/">Part 2</a>.</p>
<h2>Entities</h2>
<p><img src="/wp-content/uploads/2015/09/customizations-main.png" alt="customizations-main" width="700" height="222" class="aligncenter size-full wp-image-4605" /></p>
<p>Before we can create a workflow, we&#8217;ll need to create a new entity, Forum Update Thread. Click on the Customize the System link and it should open up a new window that will show you the Information and Components of your DCRM environment. Within Components, you&#8217;ll want to go to Entities and then New.</p>
<h3>Creating the Entity</h3>
<p><img src="/wp-content/uploads/2015/09/entities.png" alt="entities" width="700" height="431" class="aligncenter size-full wp-image-4606" /></p>
<p>Once you get the New Entity screen, set the Display Name and Plural Name. In our case, it is Forum Thread Update and Forum Thread Updates. For the remaining areas, all you need is to make sure Duplicate detection is checked under Data Services.  just select Notes and Mail merge.</p>
<p><img src="/wp-content/uploads/2015/09/entity-new.png" alt="entity-new" width="700" height="526" class="aligncenter size-full wp-image-4607" /></p>
<p>Click on Save to Create the Entity and after a minute or more, it should be done and will appear in your Entities List window.</p>
<h3>Creating Fields for the Entity</h3>
<p><img src="/wp-content/uploads/2015/09/entity-fields.png" alt="entity-fields" width="700" height="432" class="aligncenter size-full wp-image-4611" /></p>
<p>We need to create the fields that will capture the data we&#8217;re setting in the XML (script 4) file. We need the following fields.</p>
<table width="700">
<tr>
<td>
<h5>1- Forum Thread</h5>
<p>Display: Forum Thread<br />
Field Requirement: Business Required<br />
Searchable: Yes<br />
Field Security: Disable<br />
Auditing: Enable<br />
Data Type: Lookup<br />
Target Record Type: Forum Thread
</td>
<td>
<h5>2- First Post</h5>
<p>Display: First Post<br />
Field Requirement: Business Required<br />
Searchable: Yes<br />
Field Security: Disable<br />
Auditing: Enable<br />
Data Type: Lookup<br />
Target Record Type: Forum Thread
</td>
</tr>
<tr>
<td>
<h5>3- Last Post</h5>
<p>Display: Last Post<br />
Field Requirement: Optional<br />
Searchable: Yes<br />
Field Security: Disable<br />
Auditing: Enable<br />
Data Type: Lookup<br />
Target Record Type: Forum Thread
</td>
<td>
<h5>4- Post Count</h5>
<p>Display: Post Count<br />
Field Requirement: Business Required<br />
Searchable: No<br />
Field Security: Disable<br />
Auditing: Enable<br />
Data Type: Whole Number<br />
Field Type: Simple
</td>
</tr>
</table>
<p>Once you&#8217;re done, make sure to Publish your customizations.</p>
<h2>Processes and Workflows</h2>
<p><img src="/wp-content/uploads/2015/09/processes_page.png" alt="processes_page" width="700" height="99" class="aligncenter size-full wp-image-4603" /></p>
<p>At this point, you should already have the 4th XML script, which is a Forum Thread Update (adx_forum_thread_update.php). We&#8217;ll now get to the Processes page in DCRM which is located in the Settings area. And we&#8217;ll start by creating a new process.</p>
<h3>Creating a Workflow</h3>
<p><img src="/wp-content/uploads/2015/09/create-process.png" alt="create-process" width="643" height="483" class="aligncenter size-full wp-image-4609" /></p>
<p>Give it a name that you will remember and make sure to set the Category to Workflow and the Entity to Forum Thread Update. Once you&#8217;ve created it, it should be in the Processes List and the Status will be Draft. If you don&#8217;t have a pop-up blocker enabled, you should see a new window that allows you to configure the new workflow. Otherwise, click on it in the Processes list to continue with configuration.</p>
<p><img src="/wp-content/uploads/2015/09/workflow-configure.png" alt="workflow-configure" width="700" height="332" class="aligncenter size-full wp-image-4618" /></p>
<p>In the Available to Run area, chose the &#8220;As an on-demand process&#8221; option. You can also set the Scope to Organization. From there, we&#8217;ll go to Add Steps in the lower part of the page. Choose Update Record and set the field to Forum Thread and click on Set Properties.</p>
<p>In this window, first start by clicking on the &#8220;First Post&#8221; field. On the Form Assistant to the right, in the &#8220;Look for&#8221; drop-down, set it to First Post (Forum Post), click Add and press OK. It should insert the value in the &#8220;First Post&#8221; field. Do the same for the Last Post. For Post Count, the Look for should be set to Forum Thread Update and in the drop-down below it, you&#8217;ll see Post Count.</p>
<p><img src="/wp-content/uploads/2015/09/workflow-properties.png" alt="workflow-properties" width="700" height="299" class="aligncenter size-full wp-image-4620" /></p>
<p>Save and it should take you back to the initial configuration screen. Click on Activate. In the Confirmation dialogue that appears, continue with Activate. You should be returned to the Processes screen and your new process should have a status of &#8220;Activated&#8221;.</p>
<h2>Import the XML Script 4 (Forum Thread Update)</h2>
<p>We&#8217;re going to import the last XML script and this time, we&#8217;ll be mapping it to the record type, Forum Thread Update. Once you get to the Field Mapping, it should look like this.</p>
<p><img src="/wp-content/uploads/2015/09/map-fields-forum-thread-update.png" alt="map-fields-forum-thread-update" width="602" height="399" class="aligncenter size-full wp-image-4626" /></p>
<p>Once you&#8217;re done the upload, go back to the Processes page and click on the Forum Thread Update process. When it opens up, go to the Process Sessions section and you&#8217;ll see the threads being updated one by one. When this finishes, you can go to your actual Forum and will see all the posts, comments and counts present.</p>
<p><img src="/wp-content/uploads/2015/09/process-sessions.png" alt="process-sessions" width="700" height="131" class="aligncenter size-full wp-image-4628" /></p>
<p>One thing to keep in mind is that this won&#8217;t update the total Thread Count on the Forum&#8217;s properties in DCRM. You have this information in your XML Script 1 located at the bottom in the &#8220;Number&#8221; field. Enter that information in DCRM and that should complete the process.</p>
<p>Good luck with your new forums on Adxstudio!</p>
]]></content:encoded>
			<wfw:commentRss>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating Drupal 7 Forums into an Adxstudio Portal in Microsoft Dynamics – Part 2</title>
		<link>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-2/</link>
		<comments>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-2/#comments</comments>
		<pubDate>Fri, 25 Sep 2015 05:28:39 +0000</pubDate>
		<dc:creator><![CDATA[ahmeddirie]]></dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Adxstudio]]></category>
		<category><![CDATA[Data Migration]]></category>
		<category><![CDATA[DCRM]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Forums]]></category>
		<category><![CDATA[Microsoft Dynamics]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ahmeddirie.com/?p=4567</guid>
		<description><![CDATA[Continuing on from Part 1 of this post, we&#8217;re going to create the PHP scripts that will pull all of your threads, posts and comments into its own XML files. These files will then be imported into DCRM through the Import interface. Excel XML Structure The XML files have to be recognized as an Excel XML (XML Spreadsheet 2003) document. Otherwise, it just won&#8217;t work. So, we&#8217;ll go ahead and create this using some straightforward PHP. I&#8217;ve broken this up into multiple files, but you are able to do this in single files for each type (thread, post, comment, update). [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Continuing on from <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/">Part 1</a> of this post, we&#8217;re going to create the PHP scripts that will pull all of your threads, posts and comments into its own XML files. These files will then be imported into DCRM through the Import interface.</p>
<h2>Excel XML Structure</h2>
<p>The XML files have to be recognized as an Excel XML (XML Spreadsheet 2003) document. Otherwise, it just won&#8217;t work. So, we&#8217;ll go ahead and create this using some straightforward PHP. I&#8217;ve broken this up into multiple files, but you are able to do this in single files for each type (thread, post, comment, update). It&#8217;s set up so that once you visit the page through your browser, it automatically starts the download of the XML document.</p>
<h4>The Header &#8211; header.php</h4>
<p>This header is generic and you&#8217;ll be using it for all 4 scripts.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$xml_content = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Workbook xmlns=&quot;urn:schemas-microsoft-com:office:spreadsheet&quot;'.&quot;\xA&quot;;
$xml_content .= 'xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot;'.&quot;\xA&quot;;
$xml_content .= 'xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;'.&quot;\xA&quot;;
$xml_content .= 'xmlns:ss=&quot;urn:schemas-microsoft-com:office:spreadsheet&quot;'.&quot;\xA&quot;;
$xml_content .= 'xmlns:html=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;DocumentProperties xmlns=&quot;urn:schemas-microsoft-com:office:office&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Author&gt;'.$author.'&lt;/Author&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;LastAuthor&gt;'.$author.'&lt;/LastAuthor&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Created&gt;'.date('Y-m-d').'T'.date('H:i:s').'Z&lt;/Created&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Company&gt;'.$company.'&lt;/Company&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Version&gt;14.0&lt;/Version&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/DocumentProperties&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;OfficeDocumentSettings xmlns=&quot;urn:schemas-microsoft-com:office:office&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;AllowPNG/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/OfficeDocumentSettings&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ExcelWorkbook xmlns=&quot;urn:schemas-microsoft-com:office:excel&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;WindowHeight&gt;15260&lt;/WindowHeight&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;WindowWidth&gt;25600&lt;/WindowWidth&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;WindowTopX&gt;14120&lt;/WindowTopX&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;WindowTopY&gt;2480&lt;/WindowTopY&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ProtectStructure&gt;False&lt;/ProtectStructure&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ProtectWindows&gt;False&lt;/ProtectWindows&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/ExcelWorkbook&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Styles&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Style ss:ID=&quot;Default&quot; ss:Name=&quot;Normal&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Alignment ss:Vertical=&quot;Bottom&quot;/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Borders/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Font ss:FontName=&quot;Calibri&quot; x:Family=&quot;Swiss&quot; ss:Size=&quot;12&quot; ss:Color=&quot;#000000&quot;/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Interior/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;NumberFormat/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Protection/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Style&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Styles&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Worksheet ss:Name=&quot;Sheet1&quot;&gt;'.&quot;\xA&quot;;
?&gt;
</pre>
<h4>The Footer &#8211; footer.php</h4>
<p>Similar to the header, the footer is also generic. However, we are inserting the total number of records we obtained from the SQL query.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$xml_content .= '&lt;WorksheetOptions xmlns=&quot;urn:schemas-microsoft-com:office:excel&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Print&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ValidPrinterInfo/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;HorizontalResolution&gt;-4&lt;/HorizontalResolution&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;VerticalResolution&gt;-4&lt;/VerticalResolution&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Print&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;PageLayoutZoom&gt;0&lt;/PageLayoutZoom&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Selected/&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Panes&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Pane&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Number&gt;'.$num_rows.'&lt;/Number&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ActiveRow&gt;2&lt;/ActiveRow&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ActiveCol&gt;1&lt;/ActiveCol&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Pane&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Panes&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ProtectObjects&gt;False&lt;/ProtectObjects&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;ProtectScenarios&gt;False&lt;/ProtectScenarios&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/WorksheetOptions&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Worksheet&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Workbook&gt;'.&quot;\xA&quot;;
echo $xml_content;
?&gt;
</pre>
<h2>The XML Scripts</h2>
<p>We&#8217;re going to dive in a little deeper into the XML scripts we talked about in <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/">Part 1</a>. We went over the initial layout and what data each one will have. Now, we&#8217;re going to build out each script along with its respective data.</p>
<h4>XML Script 1 (Forum Threads) &#8211; adx_forum_threads.php</h4>
<p>In this file, we&#8217;re running a query to pull all of the forum threads from the database. It&#8217;s grabbing the name of the thread and the last post date. We&#8217;re manually specifying the Forum that the thread belongs to, as well as the type of thread.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
//Start the Table Header
$xml_content .= '&lt;Table ss:ExpandedColumnCount=&quot;4&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Last Post Date&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Type&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;

//Create Rows of Records
$query = 'SELECT Thread_Name, Last_Post_Date FROM forum_threads;';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
	$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;NAME OF YOUR FORUM IN DCRM&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Last_Post_Date.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;NAME OF FORUM THREAD TYPE&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;
}
mysql_close();

//End the Table
$xml_content .= '&lt;/Table&gt;'.&quot;\xA&quot;;
?&gt;
</pre>
<h4>XML Script 2 (Forum Posts) &#8211; adx_forum_posts.php</h4>
<p>With out threads set up, we now need the forum posts. We&#8217;ll running a query to pull all of the forum posts from the database. To be more specific, we&#8217;re actually pulling in the initial posts that were created for the thread. The way this works in Adxstudio is that when you are creating a new thread, it creates the thread record first and then adds the post (which is no different than a comment) to that thread.</p>
<p>So, we&#8217;re naming our first post the same as the Thread&#8217;s name. You&#8217;ll also notice that for the Author, we&#8217;re using the email address. This ensures that the post is assigned correctly (make sure the user already exists as a Contact), otherwise the import will fail if you happen to have two people with the exact same name.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
//Start the Table Header
$xml_content .= '&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Author&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Date&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Content&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;

//Create Rows of Records
$query = 'SELECT Email_Address, Thread_Name, Last_Post_Date, Content FROM forum_threads;';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
	$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Email_Address.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Last_Post_Date.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= nl2p($row-&gt;Content, false, true).&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;
}
mysql_close();

//End the Table
$xml_content .= '&lt;/Table&gt;'.&quot;\xA&quot;;
?&gt;
</pre>
<h4>XML Script 3 (Forum Comments) &#8211; adx_forum_comments.php</h4>
<p>What&#8217;s a forum post without comments? Now, we&#8217;ll run another query to pull all of the forum comments from the database. In essence, this isn&#8217;t any different than the initial post. The main difference is time (since the comment came after the first post), and that we&#8217;ve given it a unique string as a Name.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
//Start the Table Header
$xml_content .= '&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Author&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Date&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Content&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;

//Create Rows of Records
$query = 'SELECT Email_Address, Last_Post_Date, Thread_Name, unique_string, Content FROM forum_posts WHERE uid!=0;';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
	$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Email_Address.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Last_Post_Date.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;unique_string.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= nl2p($row-&gt;Content, false, true).&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;
}
mysql_close();

//End the Table
$xml_content .= '&lt;/Table&gt;'.&quot;\xA&quot;;
?&gt;
</pre>
<h4>XML Script 4 (Forum Thread Update) &#8211; adx_forum_thread_update.php</h4>
<p>In this file, we&#8217;re running a query to pull all of the forum posts along with the first post, last post and post counts. Essentially, we&#8217;re going to &#8220;update&#8221; the threads with this information. It couldn&#8217;t be done in the beginning because the First and Last Post ID&#8217;s don&#8217;t exist &#8211; so this part would fail.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
//Start the Table Header
$xml_content .= '&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;First Post&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Last Post&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Post Count&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;

//Create Rows of Records
$query = 'SELECT Thread_Name, First_Post_Id, Last_Post_Id, Post_Count FROM forum_threads;';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
	$xml_content .= '&lt;Row&gt;'.&quot;\xA&quot;;
	
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;Thread_Name.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;![CDATA['.&quot;\xA&quot;;
	$xml_content .= $row-&gt;First_Post_Id.&quot;\xA&quot;;
	$xml_content .= ']]&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Last_Post_Id.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;'.$row-&gt;Post_Count.'&lt;/Data&gt;&lt;/Cell&gt;'.&quot;\xA&quot;;
	$xml_content .= '&lt;/Row&gt;'.&quot;\xA&quot;;
}
mysql_close();

//End the Table
$xml_content .= '&lt;/Table&gt;'.&quot;\xA&quot;;
?&gt;
</pre>
<p>Note: This is the last script we&#8217;re going to import. However, a workflow has to be set up. This will be covered in Part 3.</p>
<h2>Bringing it all together</h2>
<p>Now that we have our header, footer and 4 different files, we just need to write a PHP script that will call each of the 4 scripts individually. I&#8217;ll use the threads as an example.</p>
<h4>Forum Threads XML &#8211; adx_forum_threads_xml.php</h4>
<p>The only thing to keep note of here is the file. Make sure you set the right name for your filename. It makes it easier to know what each XML file is later. You&#8217;ll notice that we added time to the filename. It keeps the filename unique in the event you were to download this more than once.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$current_time = date('h_i_s');
$filename = &quot;adx_forum_threads_&quot;.$current_time.&quot;.xml&quot;;
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename=&quot;'.$filename.'&quot;');
$author = 'YOUR NAME';
$company = 'YOUR COMPANY NAME';

//Changes new lines to paragraphs
//Found on Stack Overflow - http://stackoverflow.com/questions/7409512/new-line-to-paragraph-function
function nl2p($string, $line_breaks = true, $xml = true) {

	$string = str_replace(array('&lt;p&gt;', '&lt;/p&gt;', '&lt;br&gt;', '&lt;br /&gt;'), '', $string);

	// It is conceivable that people might still want single line-breaks
	// without breaking into a new paragraph.
	if ($line_breaks == true)
		return '&lt;p&gt;'.preg_replace(array(&quot;/([\n]{2,})/i&quot;, &quot;/([^&gt;])\n([^&lt;])/i&quot;), array(&quot;&lt;/p&gt;\n&lt;p&gt;&quot;, '$1&lt;br'.($xml == true ? ' /' : '').'&gt;$2'), trim($string)).'&lt;/p&gt;';
	else
		return '&lt;p&gt;'.preg_replace(
				array(&quot;/([\n]{2,})/i&quot;, &quot;/([\r\n]{3,})/i&quot;,&quot;/([^&gt;])\n([^&lt;])/i&quot;),
				array(&quot;&lt;/p&gt;\n&lt;p&gt;&quot;, &quot;&lt;/p&gt;\n&lt;p&gt;&quot;, '$1&lt;br'.($xml == true ? ' /' : '').'&gt;$2'),

				trim($string)).'&lt;/p&gt;';
}

require_once 'header.php';
require_once 'adx_forum_threads.php';
require_once 'footer.php';
?&gt;
</pre>
<h2>Running the Import</h2>
<p>We&#8217;ll start by going to the Forums section in DCRM and then clicking on Import Data.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/top-forums.png" alt="top-forums" width="700" height="121" class="aligncenter size-full wp-image-4576" /></p>
<p>This should bring up an Upload dialogue window. Select your XML script, e.g. forum_threads, and start the upload. Once the upload completes, you should see the following dialogue window.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/review-file-upload.png" alt="review-file-upload" width="604" height="242" class="aligncenter size-full wp-image-4586" /></p>
<p>Once you press Next, you&#8217;ll get the following dialogue window asking you to Select a Data Map. If this is your first import, stick with the default and choose Automatic Mapping. You&#8217;ll get the option to set the mapping of the data yourself. Once you&#8217;re complete, you can save this Data Map for future use so you don&#8217;t have to go through the mapping process again.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/select-data-map.png" alt="select-data-map" width="604" height="136" class="aligncenter size-full wp-image-4583" /></p>
<p>The next dialogue window will more than likely tell you it couldn&#8217;t determine what CRM Record type you&#8217;re going to be importing the forum threads to.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/map-record-types.png" alt="map-record-types" width="603" height="258" class="aligncenter size-full wp-image-4589" /></p>
<p>From the drop down list, choose Forum Thread and proceed to the next dialogue which should have your columns in your XML file mapped to the field in the DCRM record.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/map-fields.png" alt="map-fields" width="602" height="384" class="aligncenter size-full wp-image-4590" /></p>
<p>You&#8217;re now done with mapping the fields in the DCRM record type and can start importing your data. Make sure to go through the same steps with XML Scripts 1, 2 and 3. We&#8217;re skipping 4 as that involves a few extra steps.</p>
<h4>Modifying the Mapping of the Author</h4>
<p>In the XML Scripts for 2 and 3 (threads and posts), we&#8217;ve set up our script to use an email address since this is more unique than a full name. If you stick to using a full name and you have two contacts by the name of &#8220;John Doe&#8221;, the import script will fail because it won&#8217;t know who to associate the forum post to.</p>
<p>In this case, you simply change the mapping of the Author to the email address in the Contact record.</p>
<p><img src="http://ahmeddirie.com/wp-content/uploads/2015/09/map-author.png" alt="map-author" width="602" height="608" class="aligncenter size-full wp-image-4598" /></p>
<h2>What to Expect in Part 3</h2>
<p>In <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-3">Part 3</a>, we&#8217;ll go over creating Entities and Workflows within DCRM so that we could update the values on the Forum Thread (XML Script 4). This part is essential as it ties in the post with it&#8217;s comments.</p>
]]></content:encoded>
			<wfw:commentRss>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating Drupal 7 Forums into an Adxstudio Portal in Microsoft Dynamics &#8211; Part 1</title>
		<link>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/</link>
		<comments>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/#comments</comments>
		<pubDate>Mon, 21 Sep 2015 21:41:17 +0000</pubDate>
		<dc:creator><![CDATA[ahmeddirie]]></dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Adxstudio]]></category>
		<category><![CDATA[Data Migration]]></category>
		<category><![CDATA[DCRM]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal 7]]></category>
		<category><![CDATA[Forums]]></category>
		<category><![CDATA[Microsoft Dynamics]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ahmeddirie.com/?p=4545</guid>
		<description><![CDATA[I&#8217;ve been meaning to write this post for a while. Making the move to DCRM can be time consuming and much consideration is needed on how to get your data into the system. If you&#8217;ve been looking around online, you&#8217;ve probably discovered that there are a few ways where large sets of data can be imported. I&#8217;ve looked at many resources that talk about how you can get data in, and I have to admit, some are super confusing and most only cover one tiny section. As useful as they were, you never get a complete picture. In this three [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been meaning to write this post for a while. Making the move to DCRM can be time consuming and much consideration is needed on how to get your data into the system. If you&#8217;ve been looking around online, you&#8217;ve probably discovered that there are a few ways where large sets of data can be imported. I&#8217;ve looked at many resources that talk about how you can get data in, and I have to admit, some are super confusing and most only cover one tiny section. As useful as they were, you never get a complete picture. </p>
<p>In this three part post, I&#8217;ll go over how you can get your forum posts from Drupal 7, prepare it and get it imported into DCRM.</p>
<h2>Getting the Forum Data from Drupal</h2>
<p>Step 1 of course is the actual forum posts. I&#8217;m making the assumption that you are using the standard forum part of Drupal. If you&#8217;re not, the principal is the same. You can tweak the code to suit your environment. We&#8217;re going to start by getting the latest forum threads from database using an SQL query. This will include the user&#8217;s information, the forum post title, the content and the date the post was created.</p>
<pre class="brush: sql; title: ; notranslate">
SELECT n.nid AS nid, n.uid AS uid, u.mail AS 'Email_Address', n.title AS `Thread_Name`, b.body_value AS Content, n.created AS `Unix_Post_Date`
FROM node n, field_revision_body b, users u 
WHERE type=&quot;forum&quot; AND n.nid = b.entity_id AND n.uid = u.uid;
</pre>
<p>Now, armed with your forum posts, you&#8217;ll want to store this into a separate table. Preferably, you would move this into a separate database so that we don&#8217;t interfere with the live site.</p>
<p>Note: I did mention that we&#8217;ll be covering the process from end to end. However, I&#8217;m assuming that if you&#8217;ve been tasked with this job, you at least know how to copy the output you got from the last query into another table. I&#8217;ve provided the Table Creation script in the next section to ease the pain. All you have to do is export/import your data. </p>
<p>The next set of data we need is the comments that belong to each of these posts. What is a forum without comments?</p>
<pre class="brush: sql; title: ; notranslate">
SELECT c.cid AS cid, c.nid AS nid, c.uid AS uid, u.mail AS 'Email_Address', c.created AS `Unix_Post_Date`, n.title AS `Thread_Name`, c.subject AS `Re_Thread_Name`, b.comment_body_value AS Content 
FROM `comment` c, `node` n, `field_data_comment_body` b, `users` u 
WHERE c.cid = b.entity_id AND c.nid = n.nid AND c.uid = u.uid;
</pre>
<p>Now, similar to the first output, let&#8217;s do the same with comments and store this in a separate table as well.</p>
<h2>Storing the Threads and Posts</h2>
<p>This is the SQL script you&#8217;ll need to create the two new tables used to store the data you obtained in the last section.</p>
<h4>Creating the Threads Table</h4>
<p>You&#8217;ll notice that we have four extra columns we&#8217;re creating called, &#8220;Last Post Date, First Post Id, Last Post Id, Post Count&#8221;. We&#8217;re going to need these in the following section.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE `forum_threads` (
  `nid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) DEFAULT NULL,
  `Email_Address` varchar(255) NOT NULL DEFAULT '',
  `Thread_Name` varchar(255) NOT NULL DEFAULT '',
  `Content` longtext NOT NULL,
  `Unix_Post_Date` int(11) DEFAULT NULL,
  `Last_Post_Date` datetime DEFAULT NULL,
  `First_Post_Id` varchar(255) DEFAULT NULL,
  `Last_Post_Id` varchar(255) DEFAULT NULL,
  `Post_Count` int(11) DEFAULT NULL,
  PRIMARY KEY (`nid`)
) ENGINE=InnoDB AUTO_INCREMENT=1012539 DEFAULT CHARSET=utf8;
</pre>
<h4>Creating the Posts Table</h4>
<p>Like the Threads table, we have two more columns we&#8217;re creating called, &#8220;Last Post Date, Unique String&#8221;.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE `forum_posts` (
  `cid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nid` int(10) unsigned NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `Email_Address` varchar(255) NOT NULL,
  `Unix_Post_Date` int(11) NOT NULL,
  `Last_Post_Date` datetime DEFAULT NULL,
  `Thread_Name` varchar(255) NOT NULL DEFAULT '',
  `Re_Thread_Name` varchar(255) NOT NULL,
  `Content` longtext,
  `unique_string` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=1003445 DEFAULT CHARSET=utf8;
</pre>
<h2>Preparing the Data</h2>
<p>Of the ways that data can be imported into DCRM, we&#8217;re going to look at one of the simpler ways which is to use XML formatted as Excel XML documents. This should make the process easier and allows you to use the Import feature in the DCRM site and allow you to map your data to the end object.</p>
<p>Before we can continue ahead, we&#8217;ll need to fill in the new (NULL filled) columns we created earlier. We&#8217;ll start with the modifying the date of the post so that it is in a format that DCRM understands. You can use any language, but we&#8217;ll show you how to modify this using PHP.</p>
<h4>Updating the Last Post Date in the Forum Threads table</h4>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$query = 'SELECT nid, Unix_Post_Date FROM forum_threads;';
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
	
	$updated_date = gmdate(&quot;Y-m-d\TH:i:s.000&quot;, $row-&gt;Unix_Post_Date);

	$query2 = 'UPDATE forum_threads SET Last_Post_Date=&quot;'.$updated_date.'&quot; WHERE nid=&quot;'.$row-&gt;nid.'&quot;;';
	mysql_query($query2);
}
?&gt;
</pre>
<h4>Updating the Last Post Date in the Forum Posts table</h4>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$query = 'SELECT cid, Unix_Post_Date FROM forum_posts;';
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
	
	$updated_date = gmdate(&quot;Y-m-d\TH:i:s.000&quot;, $row-&gt;Unix_Post_Date);

	$query2 = 'UPDATE forum_posts SET Last_Post_Date=&quot;'.$updated_date.'&quot; WHERE cid=&quot;'.$row-&gt;cid.'&quot;;';
	mysql_query($query2);
}
?&gt;
</pre>
<h4>Creating a Unique ID for each Forum Post</h4>
<p>With Adxstudio, the forum comments works in an interesting way. This is something you probably wouldn&#8217;t have to do with Drupal since it checks what the last comment to a post is based on time. This needs to be specified in Adxstudio. We could probably get away with just using the Drupal &#8220;cid&#8221; field and check which is the last and assign it to a post. I went ahead and created a brand new unique string to attribute each post to so that there&#8217;s no confusions with other content within DCRM that may or may not have this same ID.</p>
<p>This next part can literally be done any way you like. We&#8217;re just creating a function (or three) to pass back a unique string.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

function generateRandomString($length = 60) {
	$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	$charactersLength = strlen($characters);
	$randomString = '';
	for ($i = 0; $i &lt; $length; $i++) {
		$randomString .= $characters[mt_rand(0, $charactersLength - 1)];
	}
	
	return $randomString;
}

function microtime_int() {
	list($usec, $sec) = explode(&quot; &quot;, microtime());
	return ((int)$usec + (int)$sec);
}

function createRandom() {
	
	$randomString = generateRandomString();
	$currentTime = date('yYzmMdDhis');
	$microTime = microtime_int();
	
	$newRandom = $microTime.$randomString.$currentTime;
	
	$shuffled = str_shuffle($newRandom);
	
	return $shuffled;
}

?&gt;
</pre>
<p>With that out of the way, we&#8217;ll need to now update each forum post with a unique string.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$query = 'SELECT cid FROM forum_posts;';
$result = mysql_query($query);

while ($row = mysql_fetch_object($result)) {
	$unique_id = createRandom();
	
	$query2 = 'UPDATE forum_posts SET unique_string=&quot;'.$unique_id.'&quot; WHERE cid=&quot;'.$row-&gt;cid.'&quot;;';
	mysql_query($query2);
}

?&gt;
</pre>
<h4>Updating the First Post ID, Last Post ID and Post Count for each Forum Thread</h4>
<p>This is the last part to preparing our data and wraps up the thread table with the remaining data. We&#8217;ll be setting the &#8220;First Post ID&#8221; as the title of the thread, &#8220;Last Post ID&#8221; as the unique string of the last comment to the post, and the total comments for the post which includes the initial post. This means that if there are 11 comments, the total post count should be 12 as this includes the original thread&#8217;s post.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$query = 'SELECT nid, Thread_Name FROM forum_threads;';
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
	
	$query2 = 'SELECT unique_string FROM forum_posts WHERE nid=&quot;'.$row-&gt;nid.'&quot; ORDER BY cid DESC;';
	$result2 = mysql_query($query2);
	$row2 = mysql_fetch_object($result2);
	
	for ($x = 0; $x &lt; 1; $x++) {
		$unique_string = $row2-&gt;unique_string;
	}
	
	$total_rows = mysql_num_rows($result2);
	$total_rows++;
	
	$query3 = 'UPDATE forum_threads SET First_Post_Id=&quot;'.$row-&gt;Thread_Name.'&quot;, Last_Post_Id=&quot;'.$row2-&gt;unique_string.'&quot;, Post_Count=&quot;'.$total_rows.'&quot; WHERE nid=&quot;'.$row-&gt;nid.'&quot;;';
	mysql_query($query3);
}

?&gt;
</pre>
<h2>Structure of the XML Import Scripts</h2>
<p>In this section, we&#8217;re going to break up the data in both tables into 4 separate XML scripts.</p>
<h4>XML Script 1 &#8211; Forum Threads</h4>
<p>This is the first part that gets uploaded into DCRM. You&#8217;ll notice that no IDs are used. As such, the &#8220;Thread Name&#8221; needs to be unique. You&#8217;ll notice that we&#8217;re only listing the thread name and not the actual content yet.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Table ss:ExpandedColumnCount=&quot;4&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;
&lt;Row&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Last Post Date&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Type&lt;/Data&gt;&lt;/Cell&gt;
&lt;/Row&gt;
&lt;/Table&gt;
</pre>
<h4>XML Script 2 &#8211; Forum Posts</h4>
<p>The initial content for a thread is a &#8220;Post&#8221; in DCRM. This is the second thing we import. One thing you&#8217;ll need to ensure is that you have all the author&#8217;s contact record already in DCRM. For the author field, use their email address as this is unique. For the Forum Thread field, this is referring to the &#8220;Name&#8221; field in the previous step. The &#8220;Name&#8221; field can be a unique ID as in the database.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;
&lt;Row&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Author&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Date&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Content&lt;/Data&gt;&lt;/Cell&gt;
&lt;/Row&gt;
&lt;/Table&gt;
</pre>
<p>Note: Since this is XML data being imported, you’ll want to use CDATA around the content fields.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;![CDATA[  ]]&gt;
</pre>
<h4>XML Script 3 &#8211; Forum Comments</h4>
<p>This XML is exactly like the Posts. The &#8220;Name&#8221; field will also be a unique ID as in the database. You&#8217;ll need to reference these in a fourth script where you update the main thread with first and last ID.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;
&lt;Row&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Author&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Date&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Content&lt;/Data&gt;&lt;/Cell&gt;
&lt;/Row&gt;
&lt;/Table&gt;
</pre>
<h4>XML Script 4 &#8211; Updating the Initial Forum Thread</h4>
<p>For everything to work in harmony, your threads have to know what the ID of the first post and last post is, as well as the total number of posts. Once you have this information, the XML structure for this is below.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Table ss:ExpandedColumnCount=&quot;5&quot; ss:ExpandedRowCount=&quot;1&quot; x:FullColumns=&quot;1&quot; x:FullRows=&quot;1&quot; ss:DefaultColumnWidth=&quot;65&quot; ss:DefaultRowHeight=&quot;15&quot;&gt;
&lt;Row&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Name&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Forum Thread&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;First Post&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Last Post&lt;/Data&gt;&lt;/Cell&gt;
&lt;Cell&gt;&lt;Data ss:Type=&quot;String&quot;&gt;Post Count&lt;/Data&gt;&lt;/Cell&gt;
&lt;/Row&gt;
&lt;/Table&gt;
</pre>
<p>In <a href="/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-2/">Part 2</a> of this post, I&#8217;ll cover how you can get your forum data into this XML format and get it imported into DCRM.</p>
]]></content:encoded>
			<wfw:commentRss>https://ahmeddirie.com/technology/web-development/migrating-drupal-7-forums-into-an-adxstudio-portal-in-microsoft-dynamics-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sweet Potato &amp; Smoked Salmon Egg Quiches</title>
		<link>https://ahmeddirie.com/media/videos/sweet-potato-smoked-salmon-egg-quiches/</link>
		<comments>https://ahmeddirie.com/media/videos/sweet-potato-smoked-salmon-egg-quiches/#comments</comments>
		<pubDate>Tue, 03 Mar 2015 20:31:05 +0000</pubDate>
		<dc:creator><![CDATA[ahmeddirie]]></dc:creator>
				<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://ahmeddirie.com/?p=4363</guid>
		<description><![CDATA[Meal prep the perfect post workout kick that includes protein, complex carbs and fiber. It&#8217;s super healthy and can be done in 30 minutes flat. In this video, I&#8217;ll show you how to quickly put together an awesome egg quiche with sweet potatoes, salmon and vegetables. For more awesome meals and drinks, join Tackle the Kitchen at: http://instagram.com/TackleTheKitchen http://facebook.com/TackleTheKitchen http://twitter.com/ahmeddirie http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg]]></description>
				<content:encoded><![CDATA[<p><iframe width="580" height="326" src="//www.youtube.com/embed/bTDAy3oLqgo" frameborder="0" allowfullscreen></iframe></p>
<p>Meal prep the perfect post workout kick that includes protein, complex carbs and fiber. It&#8217;s super healthy and can be done in 30 minutes flat.</p>
<p>In this video, I&#8217;ll show you how to quickly put together an awesome egg quiche with sweet potatoes, salmon and vegetables.</p>
<p>For more awesome meals and drinks, join Tackle the Kitchen at:</p>
<p><a href="http://instagram.com/TackleTheKitchen" title="Tackle the Kitchen on Instagram">http://instagram.com/TackleTheKitchen</a><br />
<a href="http://facebook.com/TackleTheKitchen" title="Tackle the Kitchen on Facebook">http://facebook.com/TackleTheKitchen</a><br />
<a href="http://twitter.com/ahmeddirie" title="Ahmed Dirie on Twitter">http://twitter.com/ahmeddirie</a><br />
<a href="http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg?sub_confirmation=1" title="Tackle the Kitchen on YouTube">http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg</a></p>
]]></content:encoded>
			<wfw:commentRss>https://ahmeddirie.com/media/videos/sweet-potato-smoked-salmon-egg-quiches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spinach and Banana Berry Smoothie</title>
		<link>https://ahmeddirie.com/media/videos/spinach-and-banana-berry-smoothie/</link>
		<comments>https://ahmeddirie.com/media/videos/spinach-and-banana-berry-smoothie/#comments</comments>
		<pubDate>Tue, 17 Feb 2015 17:55:47 +0000</pubDate>
		<dc:creator><![CDATA[ahmeddirie]]></dc:creator>
				<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://ahmeddirie.com/?p=4359</guid>
		<description><![CDATA[Drinking a green smoothie loaded with spinach, bananas, strawberries, blueberries, black berries, raspberries, pomegranate and moringa powder. For more awesome meals and drinks, join Tackle the Kitchen at: http://instagram.com/TackleTheKitchen http://facebook.com/TackleTheKitchen http://twitter.com/ahmeddirie http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg]]></description>
				<content:encoded><![CDATA[<p><iframe width="580" height="326" src="//www.youtube.com/embed/F9IQrxD6UO0" frameborder="0" allowfullscreen></iframe></p>
<p>Drinking a green smoothie loaded with spinach, bananas, strawberries, blueberries, black berries, raspberries, pomegranate and moringa powder.</p>
<p>For more awesome meals and drinks, join Tackle the Kitchen at:</p>
<p><a href="http://instagram.com/TackleTheKitchen" title="Tackle the Kitchen on Instagram">http://instagram.com/TackleTheKitchen</a><br />
<a href="http://facebook.com/TackleTheKitchen" title="Tackle the Kitchen on Facebook">http://facebook.com/TackleTheKitchen</a><br />
<a href="http://twitter.com/ahmeddirie" title="Ahmed Dirie on Twitter">http://twitter.com/ahmeddirie</a><br />
<a href="http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg?sub_confirmation=1" title="Tackle the Kitchen on YouTube">http://youtube.com/channel/UCEqDmDL3PcnvnofRmUO5Ylg</a></p>
]]></content:encoded>
			<wfw:commentRss>https://ahmeddirie.com/media/videos/spinach-and-banana-berry-smoothie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
