Casey Wise projects and web archive/sandbox

2Sep/100

Contentlet Relating in dotCMS

Pretty straight forward here.

/**
* This method create a relationship between two contentlets
* @param parent the parent of the relationship
* @param child the child of the relationship
* @param relationship the relationship that will link the two contentlets
* @param treePosition if there are more than one child, we have to set the position of this relation 
* @return the new Tree instance that represent the relationship between both contentlets
*/
 
public Tree relateContent(Contentlet parent, Contentlet child, Relationship relationship,int treePosition)
{
	//Check if there is another relation between those two entries with the same relationship
	Tree tree = TreeFactory.getTree(parent.getIdentifier(), child.getIdentifier(), relationship.getRelationTypeValue());
 
	//if the tree doesn't exist, we create a new one
	if(tree.getParent() < 1)
	{
		//Create the new instance of the relationship
		tree = new Tree(parent.getIdentifier(), child.getIdentifier(), relationship.getRelationTypeValue(), treePosition);
	}
	return tree;
}
31Aug/100

My very first bash shell script

So at work, I do some "glue" work. I'm learning all sorts of things at once. At any time during the day, I'm confident with what I'm doing or a humiliated greenhorn. Often times, where I fall short in my lack of knowledge, I shore up with a different area where I'm less dumber.  It definitely makes for a rainbow of emotions.

Today I wrote my first bash shell script and it felt really good. The code is below, but here's what it does:

  1. Queries our dotCMS database to find where we have outstanding records (that's my Java greenhorns creating those records)
  2. If records are found:
    1. SQL dumps the 2 tables to my local Ubuntu desktop
    2. Restores the data into my local data base
    3. Sends mail making use of the "mailx" software to myself and our sysadmin, notifying him to access some PHP generated SQL to run against our production dotCMS database

The PHP was generated a while ago which parses pipe-delimited data in to an ad-hoc SQL query.  This script runs hourly as a cron job.

Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
 
to="test@test.com"
 
dbh="database host path"
dbu="database user"
dpw="database password"
dbn="database name"
 
ldbh="local database host"
ldbu="local database user"
lpw="local database password"
ldb="local database name"
 
mysql -N -h $ldbh -u $ldbu -p$lpw $ldb << EOT > /tmp/t$$
select blah blah from blah blah where blah blah = blah blah blah
EOT
 
VAR=`cat /tmp/t$$`
if [ "$VAR" != "" ]; then
        echo "yes, we have unreported records\r\n$VAR"
        mysqldump --single-transaction -u $dbu -p$dpw -h $dbh $dbn table1 table2  > /tmp/tmp.sql
        mysql -u $ldbu $lbu -p$lpw $ldb &lt; /tmp/tmp.sql
        echo "Sysadmin, we have unreported records:\n$VAR\n\nCan you please run the following SQL against the prod dotCMS db?\nhttp://xxxx/xxxx.php" | mailx -s "Unreported Records" $to
fi
Tagged as: , , , No Comments
28Jul/100

Protected: dotCMS Contentlet API — Relating Content

This post is password protected. To view it please enter your password below:


30Jun/100

Protected: dotCMS SQL, multiple live contentlets and their associated unique data

This post is password protected. To view it please enter your password below:


Filed under: code, dotCMS No Comments
29Mar/100

Protected: dotCMS Plugin: XML Importer / Structer Builder

This post is password protected. To view it please enter your password below:


Filed under: code, dotCMS No Comments
19Feb/100

Protected: dotCMS SQL Calendar Events with Associated Categories

This post is password protected. To view it please enter your password below:


Filed under: code, dotCMS No Comments
13Feb/100

dotCMS SQL Query: Filtered course guide filters

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SELECT DISTINCT
	d.category_name,
	d.inode
FROM
	tree a
	INNER JOIN category b
		ON a.child = b.inode
	INNER JOIN tree c
		ON a.child = c.parent
	INNER JOIN category d
		ON c.child = d.inode
	INNER JOIN tree e
		ON c.child = e.parent
	INNER JOIN category f
		ON e.child = f.inode
		AND f.active = 1
WHERE
	a.parent = 155228
	AND c.parent = "+$parentInode
Filed under: code, dotCMS No Comments
13Feb/100

dotCMS SQL Query: Dual filtered course guides

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT DISTINCT
	c.title,
	c.inode,
	c.text_area1 as 'overview'
FROM
	category a
	INNER JOIN tree b
		ON a.inode = b.parent
	INNER JOIN contentlet c
		ON b.child  = c.inode
		AND c.live=1
	INNER JOIN tree d
		ON c.inode = d.child
	INNER JOIN category e
		ON d.parent = e.inode
	INNER JOIN tree f
		ON d.parent = f.child
WHERE
	a.inode = $inode
	AND f.parent = 155153
	AND d.parent = $filterInode
ORDER BY
	c.title
Filed under: code, dotCMS No Comments
13Feb/100

dotCMS SQL Query: 2nd level subject hierarchy categories

1
2
3
4
5
6
7
8
9
10
SELECT 
	a.child,
	b.category_name
FROM 
	tree a
	inner join category b
		on a.child = b.inode
		and b.active=1
WHERE 
	parent = 630865
Filed under: code, dotCMS No Comments
13Feb/100

dotCMS SQL Query: Available Courses Listing

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SELECT DISTINCT
	b.category_name AS 'subject_cluster',
	b.inode as 'clusterInode'
FROM
	tree a
	INNER JOIN category b
		ON a.child = b.inode
	INNER JOIN tree c
		ON a.child = c.parent
	INNER JOIN category d
		ON c.child = d.inode
	INNER JOIN tree e
		ON c.child = e.parent
	INNER JOIN category f
		ON e.child = f.inode
		AND f.active = 1
WHERE
	a.parent = 155228
Filed under: code, dotCMS No Comments