I want to create a CCK node through MySQL. I have these three main tables that I know are involved:
It appears that the Node table is used as a foriegn key for all the records in the node_revision and CCK tables. It also holds the title, create date, etc.
There are CCK tables that hold the CCK Field values
There is the the node_revision table that holds the body of the content.
Pseudocode for this might be:
Insert Into NodeTable //Title and other node fields
Select nId of New Node //To use as foreign key for insert into CCK & Revision table
Insert Into Node_Revision //body field, using NodeId as foreign key
Insert Into CCK_table //fields in form other than Title & Body
Are there any other tables that need to be touched to replicate doing it through the UI?
This is a little tricky because it depends on what other modules you have installed (ex. location) and how they hook in -- is there a reason you wouldn't want to do this "programmatically" by bootstrapping Drupal? Here's a great guide for how you could do that emulating the form module and using drupal_execute:
http://thedrupalblog.com/programmatically-create-any-node-type-using-drupal-execute
Related
I have created a view named doc_view and when i query the view I'm getting results based on view paremeters (like startkey and limit etc)
{"total_rows":103,"rows":[
{"id":"1574031792000.doc","key":"d15836415514","value":{"r":"one"}},
{"id":"1574031832000.doc","key":"d15836418914","value":{"r":"seven"}},
{"id":"14259796657.doc","key":"d1583641`enter code here`8915","value":{"r":"eleven"}},
]
}
Is there any way where I can query the view based on values (that is r field?)
Views can only be queried by key. So you have two options: Write a new view that uses that value you care about as the key, or use a Mango query.
When I tried to retrieve table using contains keyword it prompts "Cannot use CONTAINS relation on non collection column col1" but when I tried to create table using
CREATE TABLE test (id int,address map<text, int>,mail list<text>,phone set<int>,primary key (id,address,mail,phone));
it prompts "Invalid collection type for PRIMARY KEY component phone"
One of the basics in Cassandra is that you can't modify primary keys. Always keep that in mind.
You can't use a collection as primary key unless it is frozen, meaning you can't modify it.
This will work
CREATE TABLE test (id int,address frozen<map<text, int>>,mail frozen<list<text>>,phone frozen<set<int>>,primary key (id,address,mail,phone));;
However, I think you should take a look at this document: http://www.datastax.com/dev/blog/cql-in-2-1
You can put secondary indexes on collections after cql 2.1. You may want to use that functionality.
I am trying to create a slug(prettyurl) for each post added by the user. And use this slug to access the record in the db. The generated slugs might not be unique so I thought of adding the #rid at the end of the slug. So that the slugs will be unique and I can retrieve the record with the #rid while fetching the record. I can use this slug in the restful url's as well(after removing the # in the #rid).
So is there a way to append the rid to the slug property while inserting the record?
Or is there an auto increment field in orientdb which I can concatenate with the slug?
Or is there any other way to achieve the same result? I thought about generating a unique id from node js but this might add the overhead of creating and managing unique filed across multiple servers.
I am using
orientjs version: 2.1.0
orientdb version 2.1.6
Slug thing what you have explained I can not understand.
However #rid that is the Record Identifier in OrientDB is unique and it resembles like Primary Key of our Relational Database System.
to append the #rid you can use slug.append(#rid) but at the time of INSERT, it may not work as #rid is determined after the INSERT.
You can use INSERT.. RETURN #rid read it from here
However, for the Auto Increment purpose, I would say that #rid is automatically incremented. It is decided as #clusterIDOfTheRecord:positionOfTheRecordInTheCluster.
So, autoincrement there may not be needed.
I have a Content Type "News" with custom field "NewsDate" (DateTimeField) and "Active" (BooleanField)
Now I'm need to get 3 active atimes order desc by NewsDate
Get all news, make them toList() and from there manipulate the data is not a solution.
P.S. I need to do something like:
var items = contentManager
.Query(Entities[PageType.Press])
.OrderByDescending<CommonPartRecord, DateTime?>(record => record.PublishedUtc)
.Slice(0, 3);
but instead of PublishedUTC use my custom field "NewsDate" and add Active == true, However it is not possible due to Orchard architecture of storing custom data in a separate field as XML data.
UPDATED:
In a nutshell I want to generate from code behind the following Query:
DECLARE #temp as TABLE(id int, xmldata xml)
INSERT #temp VALUES(1,'<Data><News><NewsDate>07/14/2011 11:42:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(2,'<Data><News><NewsDate>07/11/2011 12:11:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link></News></Data>')
INSERT #temp VALUES(3,'<Data><News><NewsDate>02/21/2012 16:56:00</NewsDate><Link Title="" DisplayText="" Link="www.example.com" OpenInNewTab="True">www.example.com</Link><NewsLink></NewsLink></News></Data>')
SELECT
TOP 3 [id],
[xmldata].value('(Data/News/NewsDate)[1]', 'datetime') as NewsDate
FROM #temp
ORDER BY NewsDate DESC
P.S. I looked through the code for DynamicContentQueryTests, however all the examples uses the Part, and in my case Fields are just in the ContentItem:
E.g. News content type contains NewsDate field (datetime field) and some parts as well
Any suggestions are greatly appreciated.
Querying fields is possible since 1.4 through Projector and underlying index tables and new APIs on Content Manager. Your simplest bet actually may be to create a projection.
To get the values of fields that have been attached directly to a Content Item, you need to first look for the Content Part with the same name as the item, which is created by Orchard. So in your case in the Parts list for each News Content Item you'll find a part called "NewsPart", and inside this the Fields property will have your NewsDate and Active fields.
However, like you say Orchard serializes the field values into XML for storage to prevent it having to change the database structure every time you add/remove a field to/from a content type. For this reason, querying and ordering by fields is not recommended because all the serialized data needs to be de-serialized for each Content Item. If you want to be able to do this, the best way is to make your own Content Part with a Content Part Record and use your own table for storage, then you can do this:
contentManager.Query<NewsPart, NewsPartRecord>()...
...and query/sort on whatever values you like.
Bertrand is correct. Check this link : http://www.davidhayden.me/blog/projector-module-in-orchard-cms. You can implement your requirements easily with Projection Module. The link will tell you the steps to do that. If you don't want a widget, you can create a page with your query too. Once the module is enabled, you will see the option to create a Projection Page in the left hand side navigation.
EDIT :
Can't you simply parse the XML? You can query your content type 'News'. Something like -
var contentItems = contentManager.Query<ContentPart>("News").Join<TitlePartRecord>().Join<AutoroutePartRecord>().Join<CommonPartRecord>().List();
Once you have that, you can access the XML data by :
foreach (var item in contentItems)
{
var contentItem = (ContentItem)item.ContentItem;
ContentItemVersionRecord contentItemRecord = contentItem.VersionRecord;
string data = contentItemRecord.Data;
//Call some function here to parse 'data' and store the object in the list.
}
'data' has the information in XML format that you need.
You can parse it and then store the objects in your list that you can order by your custom field.
I've been working with a custom module that has a widget with some fields stored in the DB. I added a new non-required field to the widget and a corresponding field in the database is not being added. What's the best way to handle this type of change?
I can manually add a field in the dev database to match it, but this is unrealistic for 50 some odd production tenant sites.
To expand on #Bertand's answer a little, you don’t need to create database columns when you add fields (Boolean Field, Text Field, Media Picker Field etc) to content parts because the database structure for storing fields is already in place in the database.
Fields are stored as serialized XML against the content part. All of my records are stored in the Orchard_Framework_ContentItemVersionRecord table (there’s a similar table Orchard_Framework_ContentItemRecord, but that doesn’t appear to be used.
The XML is essentially of the format:
<Data>
<SomePart>
<SomeFieldName SomeFieldProperty=”value”
SomeOtherProperty=”value”>FieldValue</SomeFieldName>
</SomePart>
<SomeOtherPart>
<SomeOtherFieldName>FieldValue</SomeOtherFieldName>
</SomeOtherPart>
</Data>
So, for example you might have something like this:
<Data>
<PicturePart>
<picture AlternateText="" Class="" Style="" Alignment="" Width="1219"
Height="709">~/Media/Default/images/greatPicture.jpg</picture>
</PicturePart>
<PictureType>
<ExtraDescription>It’s a great picture!</ExtraDescription>
</Pictureype>
</Data>
Orchard uses the information from the Settings_XXXRecord tables to determine the types of the fields when it’s deserializing them back from the database.
All of this is why, as Bertand says here, fields are easier to create, but harder to query.
Looking at the solution you've posted, it looks like you're adding custom columns, rather than Orchard Fields. If this is what you're trying to do, then it seems like something you should be doing in a datamigration for your module by using AddColumn, as described here. This would look something like:
public int UpdateFrom1() {
SchemaBuilder.AlterTable("TABLE_NAME", table => table
.AddColumn<int>("mynewcolumn")
.AddColumn<string>("mynewcolumn2")
);
return 2;
}
I'm not sure if it's the ideal solution, but running an sql script that manually adds the columns to the module table for all tenants sites seems to do the trick okay. Luckily I setup all my sites to exist in the same database!
SELECT 'Alter table ' + TABLE_NAME + ' Add mynewcolumn int null,
mynewcolumn2 nvarchar(15) null' FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_NAME LIKE '%the_suffix_my_module_puts_for_a_tenant'
A field is not supposed to add a column in the database. By design.