{"id":968,"date":"2010-08-05T21:28:21","date_gmt":"2010-08-05T15:58:21","guid":{"rendered":"http:\/\/www.prasadgupte.com\/go\/?p=968"},"modified":"2014-01-12T17:57:43","modified_gmt":"2014-01-12T12:27:43","slug":"converting-csvexcel-data-to-doctrine-yaml-fixtures","status":"publish","type":"post","link":"https:\/\/www.prasadgupte.com\/blog\/converting-csvexcel-data-to-doctrine-yaml-fixtures\/","title":{"rendered":"Converting CSV\/Excel data to Doctrine YAML fixtures"},"content":{"rendered":"<p style=\"text-align: justify;\">I had done some research on this topic and found that some script was available in Python. With no knowledge of Python execution, I sought help from stackoverflow &amp; got the answer there pointed to the same Python script \ud83d\ude41 I decided I had to do something on my own! Ensuring the right no of spaces in the YAML could be a real pain &#8211; I haven&#8217;t found the error messages to be very friendly.<\/p>\n<p style=\"text-align: justify;\">My challenge was to be able to generate a YAML for a table\/schema using the nested-set behaviour in Doctrine. Instead of losing my mind on devising a human-readable format, I reverse engineered. I checked the resulting schema in the database and used that as the base for my CSV. Following this I wrote a simple macro that will output in the required format. This has evolved over a week or so, and has been thoroughly tested. I am sharing this file with 2 examples: one for the JobeetJob schema &amp; other from the Hierarchical Data page on Doctrine.<\/p>\n<p style=\"text-align: justify;\">Let me know if this helps! Vote for the answer on <a href=\"http:\/\/stackoverflow.com\/questions\/3364850\/convert-from-database-excel-csv-to-yaml-data-fixtures\" target=\"_blank\">StackOverflow<\/a>.<\/p>\n<h2 style=\"text-align: justify;\"><strong>To start using:<\/strong><\/h2>\n<ol>\n<li>Download the ZIP file<em> <a href=\"https:\/\/app.box.com\/shared\/8alqsfzc1o\">CSV\/Excel to YAML Generator v2<\/a> <\/em>&amp; unzip<em> <\/em>it.<em><br \/>\n<\/em><\/li>\n<li>Change the model name<!--more--><\/li>\n<li>If you need an explicit &#8216;<em>NestedSet: true<\/em>&#8216; declaration, then set <em>NestedSet?<\/em> cell to &#8216;<strong>Y<\/strong>&#8216; or &#8216;<strong>true<\/strong>&#8216;<\/li>\n<li>If you wish to add any PHP scripts at the beginning and end of data, you can paste it in the respective cells. <em>I often use this to loop for a number of tenants.<\/em><\/li>\n<li>Specify the sheet where you want the output to the generated.<br \/>\nIf an invalid or empty sheet name is specified, data is printed to the &#8220;Output&#8221; sheet. Hence, do not delete it.<\/li>\n<li>Replace the column names for your model, starting from the 3rd column.<\/li>\n<li>Start entering your data<\/li>\n<li>Please don&#8217;t forget the 2 &#8216;<strong>end<\/strong>&#8216; markers to mark the end of columns &amp; rows.<\/li>\n<li>Press the &#8216;<strong>Generate<\/strong>&#8216; button<\/li>\n<li>Copy the data and paste it into the <em>fixtures.yml<\/em> file<\/li>\n<\/ol>\n<h2 style=\"text-align: justify;\"><strong>Additional information:<\/strong><\/h2>\n<ol>\n<li>1st column (level) denotes the level in the nested-set. When using for flat structures, set level = <strong>0<\/strong> (zero) for all records.<\/li>\n<li>2nd column is the key, that you define for every record in the fixture. This is not saved \ud83d\ude42<\/li>\n<li>Again, please don&#8217;t forget the 2 &#8216;<strong>end<\/strong>&#8216; markers to mark the end of columns &amp; rows.<\/li>\n<li>If you need to convert data for more than one model, simply &#8216;Copy&#8217; the worksheet. As long as it caries the &#8216;<strong>Generate<\/strong>&#8216; button, the macro will intelligently output the data.<\/li>\n<li>After you press the &#8216;<strong>Generate<\/strong>&#8216; button, existing data is first deleted &#8211; so don&#8217;t take the extra pain.<\/li>\n<li>Data types are not handled in any way! So if your column is formatted as a date in some non-standard format, the macro will print it as is \ud83d\ude41<\/li>\n<li>To enter dates, you might need an extra tick to escape the first one. So &#8221;2004-10-09&#8242; will output &#8216;2004-10-09&#8217;<\/li>\n<\/ol>\n<h2 style=\"text-align: justify;\"><strong>Roadmap:<\/strong><\/h2>\n<ul>\n<li>Data from all sheets should be printed at once.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><strong>If you need any more features, feel free to ask for it OR develop &amp; share.<\/strong><\/p>\n<h2>License:<\/h2>\n<p style=\"text-align: justify;\">None, just focus on using &amp; improving it \ud83d\ude42<\/p>\n<h2 style=\"text-align: justify;\">Request:<\/h2>\n<ul>\n<li>If you host this file elsewhere, please post a link as a Comment on this page; it will help others!<\/li>\n<li>Also, if someone can move the macro to OpenOffice, this will be truly OpenSource \ud83d\ude42<\/li>\n<li>If this helps, Vote for the answer on <a href=\"http:\/\/stackoverflow.com\/questions\/3364850\/convert-from-database-excel-csv-to-yaml-data-fixtures\" target=\"_blank\">StackOverflow<\/a>.<\/li>\n<\/ul>\n<p>PS: This is my first real technology post \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had done some research on this topic and found that some script was available in Python. With no knowledge of Python execution, I sought help from stackoverflow &amp; got the answer there pointed to the same Python script \ud83d\ude41 I decided I had to do something on my own! Ensuring the right no of &hellip; <a href=\"https:\/\/www.prasadgupte.com\/blog\/converting-csvexcel-data-to-doctrine-yaml-fixtures\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Converting CSV\/Excel data to Doctrine YAML fixtures<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[514,520,510,545,517,513,515,519,518,516,101,509,511,512],"class_list":["post-968","post","type-post","status-publish","format-standard","hentry","category-data","tag-convert","tag-data-information","tag-doctrine","tag-download","tag-dummy-data","tag-fixtures","tag-generate","tag-multi-tenancy","tag-multi-tenant","tag-nested-set","tag-php","tag-symfony","tag-yaml","tag-yml"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/posts\/968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/comments?post=968"}],"version-history":[{"count":0,"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/posts\/968\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/media?parent=968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/categories?post=968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prasadgupte.com\/blog\/wp-json\/wp\/v2\/tags?post=968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}