+++ /dev/null
-<?php
-
-/**
- * ImageStyleCode.php
- *
- * PHP version 5.2
- *
- * @category Toolkit
- * @package Package
- * @author Steve Sutton <steve@gaslightmedia.com>
- * @copyright 2012 Gaslight Media
- * @license Gaslight Media
- * @version SVN: $Id$
- * @link <>
- */
-
-/**
- * ImageStyleCode
- *
- * Description of imageStyleCode
- *
- * @category Photos
- * @package Photos
- * @author Steve Sutton <steve@gaslightmedia.com>
- * @copyright 2012 Gaslight Media
- * @license Gaslight Media
- * @version Release: 1.0
- * @link <>
- */
-class ImageStyleCode
-{
- protected $id;
- protected $owner_id;
- protected $code;
- protected $filetype = 1;
- protected $descr = 'Created using Phing';
- protected $format = 'JPG';
- protected $compress_type = 8;
- protected $compression = 70;
- protected $resize = false;
- protected $size_mode = 1;
- protected $width = 287;
- protected $height = 0;
- protected $resize_filter = 0;
- protected $max_size = true;
- protected $max_width = 287;
- protected $max_height = 0;
- protected $max_storage = 0;
- protected $composite = false;
- protected $comp_image = null;
- protected $comp_type = 40;
- protected $comp_x = 0;
- protected $comp_y = 0;
- protected $comp_rel_pos = 1;
- protected $border = false;
- protected $border_color = null;
- protected $border_x = 0;
- protected $border_y = 0;
- protected $commands = null;
- protected $resolution_x = 72;
- protected $resolution_y = 72;
- protected $resolution = false;
- protected $resize_blur = 1;
- protected $resolution_blur = 1;
- protected $resolution_filter = 0;
- protected $aspect_ratio = false;
- protected $trim_h = 0;
- protected $trim_w = 0;
- protected $aspect_h = 1;
- protected $aspect_w = 1;
- protected $no_expand = false;
-
- private function __construct($values)
- {
- extract($values);
- $this->setAspect_h($aspect_h)
- ->setAspect_ratio($aspect_ratio)
- ->setAspect_w($aspect_w)
- ->setBorder($border)
- ->setBorder_color($border_color)
- ->setBorder_x($border_x)
- ->setBorder_y($border_y)
- ->setCode($code)
- ->setCommands($commands)
- ->setComp_image($comp_image)
- ->setComp_rel_pos($comp_rel_pos)
- ->setComp_type($comp_type)
- ->setComp_x($comp_x)
- ->setComp_y($comp_y)
- ->setComposite($composite)
- ->setCompress_type($compress_type)
- ->setCompression($compression)
- ->setDescr($descr)
- ->setFiletype($filetype)
- ->setFormat($format)
- ->setHeight($height)
- ->setMax_height($max_height)
- ->setMax_size($max_size)
- ->setMax_storage($max_storage)
- ->setMax_width($max_width)
- ->setNo_expand($no_expand)
- ->setOwner_id($owner_id)
- ->setResize($resize)
- ->setResize_blur($resize_blur)
- ->setResize_filter($resize_filter)
- ->setResolution($resolution)
- ->setResolution_filter($resolution_filter)
- ->setResolution_blur($resolution_blur)
- ->setResolution_x($resolution_x)
- ->setResolution_y($resolution_y)
- ->setSize_mode($size_mode)
- ->setTrim_h($trim_h)
- ->setTrim_w($trim_w)
- ->setWidth($width);
- if ($id) {
- $this->setId($id);
- }
- return $this;
- }
-
-
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * sets the id of object
- *
- * @param Int $id set the id of object if not numeric throw Exception
- *
- * @return Toolkit_Table
- */
- public function setId($id)
- {
- if (!is_numeric($id)) {
- throw new Exception('id must be an integer');
- }
- if (!$this->id) {
- $this->id = $id;
- }
- return $this;
- }
-
- public function getOwner_id()
- {
- return $this->owner_id;
- }
-
- public function setOwner_id($owner_id)
- {
- $this->owner_id = $owner_id;
- return $this;
- }
-
- public function getCode()
- {
- return $this->code;
- }
-
- public function setCode($code)
- {
- $this->code = $code;
- return $this;
- }
-
- public function getFiletype()
- {
- return $this->filetype;
- }
-
- public function setFiletype($filetype)
- {
- $this->filetype = $filetype;
- return $this;
- }
-
- public function getDescr()
- {
- return $this->descr;
- }
-
- public function setDescr($descr)
- {
- $this->descr = $descr;
- return $this;
- }
-
- public function getFormat()
- {
- return $this->format;
- }
-
- public function setFormat($format)
- {
- $this->format = $format;
- return $this;
- }
-
- public function getCompress_type()
- {
- return $this->compress_type;
- }
-
- public function setCompress_type($compress_type)
- {
- $this->compress_type = $compress_type;
- return $this;
- }
-
- public function getCompression()
- {
- return $this->compression;
- }
-
- public function setCompression($compression)
- {
- $this->compression = $compression;
- return $this;
- }
-
- public function getResize()
- {
- return $this->resize;
- }
-
- public function setResize($resize)
- {
- $this->resize = $resize;
- return $this;
- }
-
- public function getSize_mode()
- {
- return $this->size_mode;
- }
-
- public function setSize_mode($size_mode)
- {
- $this->size_mode = $size_mode;
- return $this;
- }
-
- public function getWidth()
- {
- return $this->width;
- }
-
- public function setWidth($width)
- {
- $this->width = $width;
- return $this;
- }
-
- public function getHeight()
- {
- return $this->height;
- }
-
- public function setHeight($height)
- {
- $this->height = $height;
- return $this;
- }
-
- public function getResize_filter()
- {
- return $this->resize_filter;
- }
-
- public function setResize_filter($resize_filter)
- {
- $this->resize_filter = $resize_filter;
- return $this;
- }
-
- public function getMax_size()
- {
- return $this->max_size;
- }
-
- public function setMax_size($max_size)
- {
- $this->max_size = $max_size;
- return $this;
- }
-
- public function getMax_width()
- {
- return $this->max_width;
- }
-
- public function setMax_width($max_width)
- {
- $this->max_width = $max_width;
- return $this;
- }
-
- public function getMax_height()
- {
- return $this->max_height;
- }
-
- public function setMax_height($max_height)
- {
- $this->max_height = $max_height;
- return $this;
- }
-
- public function getMax_storage()
- {
- return $this->max_storage;
- }
-
- public function setMax_storage($max_storage)
- {
- $this->max_storage = $max_storage;
- return $this;
- }
-
- public function getComposite()
- {
- return $this->composite;
- }
-
- public function setComposite($composite)
- {
- $this->composite = $composite;
- return $this;
- }
-
- public function getComp_image()
- {
- return $this->comp_image;
- }
-
- public function setComp_image($comp_image)
- {
- $this->comp_image = $comp_image;
- return $this;
- }
-
- public function getComp_type()
- {
- return $this->comp_type;
- }
-
- public function setComp_type($comp_type)
- {
- $this->comp_type = $comp_type;
- return $this;
- }
-
- public function getComp_x()
- {
- return $this->comp_x;
- }
-
- public function setComp_x($comp_x)
- {
- $this->comp_x = $comp_x;
- return $this;
- }
-
- public function getComp_y()
- {
- return $this->comp_y;
- }
-
- public function setComp_y($comp_y)
- {
- $this->comp_y = $comp_y;
- return $this;
- }
-
- public function getComp_rel_pos()
- {
- return $this->comp_rel_pos;
- }
-
- public function setComp_rel_pos($comp_rel_pos)
- {
- $this->comp_rel_pos = $comp_rel_pos;
- return $this;
- }
-
- public function getBorder()
- {
- return $this->border;
- }
-
- public function setBorder($border)
- {
- $this->border = $border;
- return $this;
- }
-
- public function getBorder_color()
- {
- return $this->border_color;
- }
-
- public function setBorder_color($border_color)
- {
- $this->border_color = $border_color;
- return $this;
- }
-
- public function getBorder_x()
- {
- return $this->border_x;
- }
-
- public function setBorder_x($border_x)
- {
- $this->border_x = $border_x;
- return $this;
- }
-
- public function getBorder_y()
- {
- return $this->border_y;
- }
-
- public function setBorder_y($border_y)
- {
- $this->border_y = $border_y;
- return $this;
- }
-
- public function getCommands()
- {
- return $this->commands;
- }
-
- public function setCommands($commands)
- {
- $this->commands = $commands;
- return $this;
- }
-
- public function getResolution_x()
- {
- return $this->resolution_x;
- }
-
- public function setResolution_x($resolution_x)
- {
- $this->resolution_x = $resolution_x;
- return $this;
- }
-
- public function getResolution_y()
- {
- return $this->resolution_y;
- }
-
- public function setResolution_y($resolution_y)
- {
- $this->resolution_y = $resolution_y;
- return $this;
- }
-
- public function getResolution()
- {
- return $this->resolution;
- }
-
- public function setResolution($resolution)
- {
- $this->resolution = $resolution;
- return $this;
- }
-
- public function getResize_blur()
- {
- return $this->resize_blur;
- }
-
- public function setResize_blur($resize_blur)
- {
- $this->resize_blur = $resize_blur;
- return $this;
- }
-
- public function getResolution_blur()
- {
- return $this->resolution_blur;
- }
-
- public function setResolution_blur($resolution_blur)
- {
- $this->resolution_blur = $resolution_blur;
- return $this;
- }
-
- public function getResolution_filter()
- {
- return $this->resolution_filter;
- }
-
- public function setResolution_filter($resolution_filter)
- {
- $this->resolution_filter = $resolution_filter;
- return $this;
- }
-
- public function getAspect_ratio()
- {
- return $this->aspect_ratio;
- }
-
- public function setAspect_ratio($aspect_ratio)
- {
- $this->aspect_ratio = $aspect_ratio;
- return $this;
- }
-
- public function getTrim_h()
- {
- return $this->trim_h;
- }
-
- public function setTrim_h($trim_h)
- {
- $this->trim_h = $trim_h;
- return $this;
- }
-
- public function getTrim_w()
- {
- return $this->trim_w;
- }
-
- public function setTrim_w($trim_w)
- {
- $this->trim_w = $trim_w;
- return $this;
- }
-
- public function getAspect_h()
- {
- return $this->aspect_h;
- }
-
- public function setAspect_h($aspect_h)
- {
- $this->aspect_h = $aspect_h;
- return $this;
- }
-
- public function getAspect_w()
- {
- return $this->aspect_w;
- }
-
- public function setAspect_w($aspect_w)
- {
- $this->aspect_w = $aspect_w;
- return $this;
- }
-
- public function getNo_expand()
- {
- return $this->no_expand;
- }
-
- public function setNo_expand($no_expand)
- {
- $this->no_expand = $no_expand;
- return $this;
- }
-
- /**
- * insert the object
- *
- * @param PDO $dbh Database Connection
- *
- * @return Toolkit_Table
- */
- public function insert(PDO $dbh)
- {
-
- try {
- $values = get_object_vars($this);
- unset($values['id']);
- $columns = array_keys($values);
- $params = implode(', ', $columns);
- $bindParams = ':' . implode(', :', $columns);
-
- $sql = "
- INSERT INTO iscs
- ($params)
- VALUES
- ($bindParams)
- RETURNING id";
- $stmt = $dbh->prepare($sql);
- foreach ($values as $k => &$v) {
- if (is_integer($v)) {
- $dataType = PDO::PARAM_INT;
- } else if (is_bool($v)) {
- $dataType = PDO::PARAM_BOOL;
- } else {
- $dataType = PDO::PARAM_STR;
- }
- // for empty values that are not actually a zero (0), we
- // want to insert null's.
- // as empty values '', are not considered unique
- if ( empty($v)
- && $dataType !== PDO::PARAM_BOOL
- && $dataType !== PDO::PARAM_INT
- ) {
- $v = null;
- $dataType = PDO::PARAM_NULL;
- }
- $stmt->bindParam(":$k", $v, $dataType);
- }
-
- $stmt->execute();
- $this->setId($stmt->fetchColumn());
- return $this;
- } catch(PDOException $e) {
- throw new RuntimeException("Error insert on {$e->getMessage()}");
- }
- }
-
- /**
- * Checks the id of the object if it is set then calls update othervise
- * calls insert function
- *
- * @param PDO $dbh Database connection
- *
- * @return viod
- */
- public function save(PDO $dbh)
- {
- if ($this->id) {
- $this->update($dbh);
- } else {
- $this->insert($dbh);
- }
- }
-
- /**
- * update the object
- *
- * @param PDO $dbh Database connection
- *
- * @return Toolkit_Table
- */
- public function update(PDO $dbh)
- {
- return false;
- try {
- $values = get_object_vars($this);
- unset($values['tableName']);
- $sql = Toolkit_Common::createSQLUpdate(
- $this->tableName,
- array_keys($values),
- array('id = :id')
- );
- $stmt = Toolkit_Common::prepareQuery(
- $dbh,
- $this->tableName,
- $sql,
- $values
- );
- $stmt->execute();
- return $this;
- } catch(PDOException $e) {
- throw new RuntimeException("Error update on {$e->getMessage()}");
- }
- }
-
- /**
- * Create a class object that has the given values from an array
- *
- * @param Array $values Array of values to set the class properties to
- *
- * @return Object
- */
- public static function createByValues($values)
- {
- return new ImageStyleCode($values);
- }
-
-}
+++ /dev/null
-<?php
-
-/**
- * File Server site setup
- *
- * This file is an extension of PHING used to setup and deploy sites.
- * This custom task locates existing file server records so we can obtain
- * the owner_id and passwd to set in the config files. If an existing record
- * cannot be found then a new record for this client is inserted and those
- * credentials are used in the config file
- *
- * PHP version 5
- *
- * The license text...
- *
- * @category Phing
- * @package Phing_FileServer
- * @author Jamie Kahgee <jamie@gaslightmedia.com>
- * @copyright 2010 Jamie Kahgee
- * @license http://www.gaslightmedia.com/ Gaslightmedia
- * @version CVS: $Id:$
- * @link <>
- * @see References to other sections (if any)...
- */
-
-/**
- * File Server site setup
- *
- * This file is an extension of PHING used to setup and deploy sites.
- * This custom task locates existing file server records so we can obtain
- * the owner_id and passwd to set in the config files. If an existing record
- * cannot be found then a new record for this client is inserted and those
- * credentials are used in the config file
- *
- * @category Phing
- * @package Phing_FileServer
- * @author Jamie Kahgee <jamie@gaslightmedia.com>
- * @copyright 2010 Jamie Kahgee
- * @license http://www.gaslightmedia.com/ Gaslightmedia
- * @version Release: @package_version@
- * @link <>
- * @see References to other sections (if any)...
- */
-class Phing_FileServer_Setup extends Task
-{
-
- /**
- * Host the db is on
- * @var unknown
- * @access private
- */
- private $_host = null;
-
- /**
- * User to connect to db as
- * @var unknown
- * @access private
- */
- private $_user = null;
-
- /**
- * Name of db
- * @var unknown
- * @access private
- */
- private $_dbname = null;
-
- /**
- * Database handler
- * @var object
- * @access private
- */
- private $_dbh = null;
-
- /**
- * Site name we are working on
- * @var unknown
- * @access private
- */
- private $_siteName = null;
-
- /**
- * File server client user name
- * @var unknown
- * @access private
- */
- private $_username = null;
-
- /**
- * File server client password
- * @var unknown
- * @access private
- */
- private $_password = null;
-
- /**
- * Set the database to use
- *
- * @param string $dbname database name
- *
- * @return void
- * @access public
- */
- public function setDbname($dbname)
- {
- $this->_dbname = $dbname;
- }
-
- /**
- * Sets the host
- *
- * @param string $host host the db is on
- *
- * @return void
- * @access public
- */
- public function setHost($host)
- {
- $this->_host = $host;
- }
-
- /**
- * Set the file server client password
- *
- * @param string $pword file server client password
- *
- * @return void
- * @access public
- */
- public function setPassword($pword)
- {
- $this->_password = $pword;
- }
-
- /**
- * Set the sitename
- *
- * @param string $siteName Sitename
- *
- * @return void
- * @access public
- */
- public function setSiteName($siteName)
- {
- $this->_siteName = $siteName;
- }
-
- /**
- * Set the user
- *
- * @param string $user User to connect to db as
- *
- * @return void
- * @access public
- */
- public function setUser($user)
- {
- $this->_user = $user;
- }
-
- /**
- * Set the file server client username
- *
- * @param string $uname file server username
- *
- * @return void
- * @access public
- */
- public function setUsername($uname)
- {
- $this->_username = $uname;
- }
-
- /**
- * extra initialzation steps
- *
- * The init method gets called when the <taskname> xml element closes.
- * It must be implemented even if it does nothing. You can do init steps
- * here required to setup your task object properly. After calling the
- * Init-Method the task object remains untouched by the parser. Init should
- * not perform operations related somehow to the action the task performs.
- * An example of using init may be cleaning up a variable
- * (i.e. trim($this->_variable)) or importing additional workers needed for
- * this task.
- *
- * The init method should return true or an error object evaluated by the
- * goverining logic. If you don't implement init method, phing will
- * shut down with a fatal error.
- *
- * @return void
- * @access public
- */
- public function init()
- {
- }
-
- /**
- * Entry point to execute the task
- *
- * There is exactly one entry point to execute the task. It is called
- * after the complete buildfile has been parsed and all targets and tasks
- * have been scheduled for execution. From this point forward the very
- * implementation of the tasks action starts.
- *
- * @return void
- * @access public
- */
- public function main()
- {
- $dsn = "pgsql:host={$this->_host} user={$this->_user} dbname={$this->_dbname}";
- $driverOptions = array(
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- );
-
- $this->_dbh = new PDO($dsn, null, null, $driverOptions);
- $this->_dbh->setAttribute(
- PDO::ATTR_ERRMODE,
- PDO::ERRMODE_EXCEPTION
- );
- $credentials = $this->_getFileServerCredentials();
- $this->project->setProperty($this->_username, $credentials['owner_id']);
- $this->project->setProperty($this->_password, $credentials['passwd']);
- }
-
- /**
- * Create a new user in the file server db
- *
- * @return array new client credentials
- * @access private
- * @throws RuntimeException on PDO Error
- */
- private function _createNewUserCredentials()
- {
- $credentials = array(
- 'owner_id' => strtolower(preg_replace("/\W/", "", $this->_siteName)),
- 'passwd' => $this->_createRandomPassword()
- );
- try {
- $sql = "
- INSERT INTO owners (name, owner_id, descr, passwd, active)
- VALUES (:name, :owner_id, :descr, :passwd, true)";
-
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':name', $this->_siteName, PDO::PARAM_STR);
- $stmt->bindValue(':descr', "New record automatically created from PHING setup script", PDO::PARAM_STR);
- $stmt->bindParam(':owner_id', $credentials['owner_id'], PDO::PARAM_STR);
- $stmt->bindParam(':passwd', $credentials['passwd'], PDO::PARAM_STR);
- $stmt->execute();
- } catch (PDOException $e) {
- throw new RuntimeException("Error creating credentials {$e->getMessage()}");
- }
- echo "Creating file server credentials for new record\n";
- echo "owner_id: {$credentials['owner_id']}\n";
- echo "passwd: {$credentials['passwd']}\n";
-
- return $credentials;
- }
-
- /**
- * Generates a random password for the client
- *
- * @return string Random password
- * @access private
- */
- private function _createRandomPassword()
- {
- $chars = 'abcdefghkmnpqrstuvwxyz23456789';
- srand((double)microtime() * 1000000);
- $i = 0;
- $pass = '';
-
- while ($i <= 7) {
- $num = rand() % 29;
- if (rand(0, 1)) {
- $pass .= substr($chars, $num, 1);
- } else {
- $pass .= strtoupper(substr($chars, $num, 1));
- }
- ++$i;
- }
-
- return $pass;
- }
-
- /**
- * Locates username and password of existing client by sitename
- *
- * @return mixed return value of this function on success depends on fetch
- * type. In all cases, FALSE is returned on failure.
- * @access private
- * @throws RuntimeException on PDO error
- */
- private function _getExistingCredentials()
- {
- try {
- $sql = "
- SELECT *
- FROM owners
- WHERE owner_id = :siteNameShort";
-
- $stmt = $this->_dbh->prepare($sql);
- $ownerIdName = strtolower(preg_replace("/\W/", "", $this->_siteName));
- $stmt->bindParam(':siteNameShort', $ownerIdName, PDO::PARAM_STR);
- $stmt->execute();
-
- return $stmt->fetch();
- } catch (PDOException $e) {
- throw new RuntimeException("Error fetching credentials {$e->getMessage()}");
- }
- }
-
- /**
- * Gets the clients credentials from the file server
- *
- * @return array client credentials
- * @access private
- */
- private function _getFileServerCredentials()
- {
- $credentials = $this->_getExistingCredentials();
- if ( $credentials !== false
- && is_array($credentials)
- && !empty($credentials)
- ) {
- echo "Setting file server credentials from existing record\n";
- echo "owner_id: {$credentials['owner_id']}\n";
- echo "passwd: {$credentials['passwd']}\n";
- return $credentials;
- } else {
- return $this->_createNewUserCredentials();
- }
- }
-
-}
+++ /dev/null
-<?php
-
-/**
- * ToolboxImage.php
- *
- * PHP version 5.2
- *
- * @category Toolkit
- * @package Package
- * @author Steve Sutton <steve@gaslightmedia.com>
- * @copyright 2012 Gaslight Media
- * @license Gaslight Media
- * @version SVN: (0.1)
- * @link <>
- */
-
-require_once 'ImageStyleCode.php';
-/**
- * Toolkit_Package_ToolboxImage
- *
- * Description of ToolboxImage
- *
- * @category Toolkit
- * @package Package
- * @author Steve Sutton <steve@gaslightmedia.com>
- * @copyright 2012 Gaslight Media
- * @license Gaslight Media
- * @release Release: (0.1)
- * @link <>
- */
-class Phing_FileServer_ToolboxImage
- extends Task
-{
-
- /**
- * Host the db is on
- * @var unknown
- * @access private
- */
- private $_host = null;
-
- /**
- * User to connect to db as
- * @var unknown
- * @access private
- */
- private $_user = null;
-
- /**
- * Name of db
- * @var unknown
- * @access private
- */
- private $_dbname = null;
-
- /**
- * Database handler
- * @var object
- * @access private
- */
- private $_dbh = null;
-
- /**
- * Path of the config file
- * @var unknown
- * @access private
- */
- private $_configPath = null;
-
- /**
- * Image style code
- * @var type
- * @access private
- */
- private $_imageCode = null;
-
- /**
- * Sets the imageCode
- *
- * @param type $imageCode Name of the image style
- *
- * @return void
- * @access public
- */
- public function setImageCode($imageCode)
- {
- $this->_imageCode = $imageCode;
- }
-
- /**
- * Set the database to use
- *
- * @param string $dbname database name
- *
- * @return void
- * @access public
- */
- public function setDbname($dbname)
- {
- $this->_dbname = $dbname;
- }
-
- /**
- * Set the user
- *
- * @param string $user User to connect to db as
- *
- * @return void
- * @access public
- */
- public function setUser($user)
- {
- $this->_user = $user;
- }
-
- /**
- * Sets the host
- *
- * @param string $host host the db is on
- *
- * @return void
- * @access public
- */
- public function setHost($host)
- {
- $this->_host = $host;
- }
-
- /**
- * Set the file server client password
- *
- * @param string $pword file server client password
- *
- * @return void
- * @access public
- */
- public function setPassword($pword)
- {
- $this->_password = $pword;
- }
-
- /**
- * Set the config path
- *
- * @param string $configPath Path to Config file
- *
- * @return void
- * @access public
- */
- public function setConfigPath($configPath)
- {
- $this->_configPath = $configPath;
- }
-
- /**
- * extra initialzation steps
- *
- * The init method gets called when the <taskname> xml element closes.
- * It must be implemented even if it does nothing. You can do init steps
- * here required to setup your task object properly. After calling the
- * Init-Method the task object remains untouched by the parser. Init should
- * not perform operations related somehow to the action the task performs.
- * An example of using init may be cleaning up a variable
- * (i.e. trim($this->_variable)) or importing additional workers needed for
- * this task.
- *
- * The init method should return true or an error object evaluated by the
- * goverining logic. If you don't implement init method, phing will
- * shut down with a fatal error.
- *
- * @return void
- * @access public
- */
- public function init()
- {
- }
-
- /**
- * Entry point to execute the task
- *
- * There is exactly one entry point to execute the task. It is called
- * after the complete buildfile has been parsed and all targets and tasks
- * have been scheduled for execution. From this point forward the very
- * implementation of the tasks action starts.
- *
- * @return void
- * @access public
- */
- public function main()
- {
- $dsn = "pgsql:host={$this->_host} user={$this->_user} dbname={$this->_dbname}";
- $driverOptions = array(
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- );
-
- $this->_dbh = new PDO($dsn, null, null, $driverOptions);
- $this->_dbh->setAttribute(
- PDO::ATTR_ERRMODE,
- PDO::ERRMODE_EXCEPTION
- );
- $ownerId = $this->_getOwnerId();
- if ($ownerId) {
- $this->_hasImageStyle($ownerId);
- } else {
- throw new RuntimeException('no owner id found!');
- }
- }
-
- private function _getOwnerId()
- {
- $config = parse_ini_file($this->_configPath, true);
- $ownerId = $config['production']['file_server.owner_id'];
- return $this->_getExistingCredentials($ownerId);
- }
-
- private function _hasImageStyle($ownerId)
- {
- try {
- $sql = "
- SELECT id
- FROM iscs
- WHERE owner_id = :id
- AND code = :code";
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':id', $ownerId, PDO::PARAM_INT);
- $stmt->bindParam(':code', $this->_imageCode);
- $stmt->execute();
- $id = $stmt->fetchColumn();
- if ($id) {
- echo "Image Style {$this->_imageCode} already exists\n";
- } else {
- echo "no id found for {$this->_imageCode} imageStyle\n";
- $this->_createToolboxImageStyle($ownerId);
- }
- } catch(PDOException $e) {
- throw new RuntimeException("Error fetching tbs1 {$e->getMessage()}");
- }
- }
-
- /**
- * Locates username and password of existing client by sitename
- *
- * @return mixed return value of this function on success depends on fetch
- * type. In all cases, FALSE is returned on failure.
- * @access private
- * @throws RuntimeException on PDO error
- */
- private function _getExistingCredentials($ownerId)
- {
- try {
- $sql = "
- SELECT id
- FROM owners
- WHERE owner_id = :ownerId";
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':ownerId', $ownerId, PDO::PARAM_STR);
- $stmt->execute();
- return $stmt->fetchColumn();
- } catch (PDOException $e) {
- throw new RuntimeException(
- "Error fetching credentials {$e->getMessage()}"
- );
- }
- }
-
- public function _createToolboxImageStyle($ownerId)
- {
- try {
- $sql = "
- SELECT *
- FROM iscs
- WHERE owner_id = 1
- AND code = :code";
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':code', $this->_imageCode);
- $stmt->execute();
- $values = $stmt->fetch();
- } catch(PDOException $e) {
- throw new RuntimeException("Error fetching tbs1 {$e->getMessage()}");
- }
- $values['owner_id'] = $ownerId;
- unset($values['id']);
- $imageStyle = ImageStyleCode::createByValues($values);
- $imageStyle->save($this->_dbh);
- echo "Creating Image style {$this->_imageCode}\n";
- }
-
-}
+++ /dev/null
-<?php
-
-/**
- * File Server site setup
- *
- * This file is an extension of PHING used to setup and deploy sites.
- * This custom task locates existing file server records so we can obtain
- * the owner_id and passwd to set in the config files. If an existing record
- * cannot be found then a new record for this client is inserted and those
- * credentials are used in the config file
- *
- * PHP version 5
- *
- * The license text...
- *
- * @category Phing
- * @package Phing_FileServer
- * @author Jamie Kahgee <jamie@gaslightmedia.com>
- * @copyright 2010 Jamie Kahgee
- * @license http://www.gaslightmedia.com/ Gaslightmedia
- * @version CVS: $Id:$
- * @link <>
- * @see References to other sections (if any)...
- */
-
-/**
- * File Server site setup
- *
- * This file is an extension of PHING used to setup and deploy sites.
- * This custom task locates existing file server records so we can obtain
- * the owner_id and passwd to set in the config files. If an existing record
- * cannot be found then a new record for this client is inserted and those
- * credentials are used in the config file
- *
- * @category Phing
- * @package Phing_FileServer
- * @author Jamie Kahgee <jamie@gaslightmedia.com>
- * @copyright 2010 Jamie Kahgee
- * @license http://www.gaslightmedia.com/ Gaslightmedia
- * @version Release: @package_version@
- * @link <>
- * @see References to other sections (if any)...
- */
-class Phing_Member_Setup extends Task
-{
-
- /**
- * Host the db is on
- * @var unknown
- * @access private
- */
- private $_host = null;
-
- /**
- * User to connect to db as
- * @var unknown
- * @access private
- */
- private $_user = null;
-
- /**
- * Name of db
- * @var unknown
- * @access private
- */
- private $_dbname = null;
-
- /**
- * Database handler
- * @var object
- * @access private
- */
- private $_dbh = null;
-
- /**
- * Page Name
- * @var unknown
- * @access private
- */
- private $_pageName = null;
-
- /**
- * Page id
- * @var unknown
- * @access private
- */
- private $_pageId = null;
- /**
- * Parent id
- * @var unknown
- * @access private
- */
- private $_parent = null;
-
- /**
- * Set the database to use
- *
- * @param string $dbname database name
- *
- * @return void
- * @access public
- */
- public function setDbname($dbname)
- {
- $this->_dbname = $dbname;
- }
-
- /**
- * Sets the host
- *
- * @param string $host host the db is on
- *
- * @return void
- * @access public
- */
- public function setHost($host)
- {
- $this->_host = $host;
- }
-
- /**
- * Set the pagename
- *
- * @param string $pageName Page Name
- *
- * @return void
- * @access public
- */
- public function setPageName($pageName)
- {
- $this->_pageName = $pageName;
- }
-
- /**
- * Set the user
- *
- * @param string $user User to connect to db as
- *
- * @return void
- * @access public
- */
- public function setUser($user)
- {
- $this->_user = $user;
- }
-
- /**
- * Set the page id
- *
- * @param int $pageId Page id
- *
- * @return void
- * @access public
- */
- public function setPageId($pageId)
- {
- $this->_pageId = $pageId;
- }
-
- /**
- * Set the parent id
- *
- * @param int $parent Parent id
- *
- * @return void
- * @access public
- */
- public function setParent($parent)
- {
- $this->_parent = $parent;
- }
-
- /**
- * extra initialzation steps
- *
- * The init method gets called when the <taskname> xml element closes.
- * It must be implemented even if it does nothing. You can do init steps
- * here required to setup your task object properly. After calling the
- * Init-Method the task object remains untouched by the parser. Init should
- * not perform operations related somehow to the action the task performs.
- * An example of using init may be cleaning up a variable
- * (i.e. trim($this->_variable)) or importing additional workers needed for
- * this task.
- *
- * The init method should return true or an error object evaluated by the
- * goverining logic. If you don't implement init method, phing will
- * shut down with a fatal error.
- *
- * @return void
- * @access public
- */
- public function init()
- {
- }
-
- /**
- * Entry point to execute the task
- *
- * There is exactly one entry point to execute the task. It is called
- * after the complete buildfile has been parsed and all targets and tasks
- * have been scheduled for execution. From this point forward the very
- * implementation of the tasks action starts.
- *
- * @return void
- * @access public
- */
- public function main()
- {
- $dsn
- = "pgsql:host={$this->_host} user={$this->_user} dbname={$this->_dbname}";
- $driverOptions = array(
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- );
-
- $this->_dbh = new PDO($dsn, null, null, $driverOptions);
- $this->_dbh->setAttribute(
- PDO::ATTR_ERRMODE,
- PDO::ERRMODE_EXCEPTION
- );
- $pageId = $this->_createPage($this->_pageName, $this->_parent);
- $this->_createParagraph($pageId);
- $this->project->setProperty(
- $this->_pageId,
- $pageId
- );
- }
-
- /**
- * Create a page given a parent id
- *
- * The page will be given the next position available for it
- *
- * @param string $pageName Name of the Page (navigation_name)
- *
- * @param int $parent Parent page to attach page to
- *
- * @return int
- * @throws RuntimeException
- */
- private function _createPage($pageName, $parent)
- {
- try {
- $sql = "
- INSERT INTO toolbox.pages
- (active, template, parent, pos, navigation_name)
- VALUES
- (TRUE, 1, :parent, (SELECT count(id)
- FROM toolbox.pages
- WHERE parent = :parent) + 1, :navigation_name)
- RETURNING id";
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':parent', $parent, PDO::PARAM_INT);
- $stmt->bindParam(':navigation_name', $pageName);
- $stmt->execute();
- $pageId = $stmt->fetchColumn();
- return $pageId;
- } catch(PDOException $e) {
- throw new RuntimeException(
- "Error creating page {$e->getMessage()}"
- );
- }
- }
-
- /**
- * Create a paragraph for the page using pageId
- *
- * @param type $pageId Page to create paragraph for
- *
- * @return boolean
- * @throws RuntimeException
- */
- private function _createParagraph($pageId)
- {
- try {
- $sql = "
- INSERT INTO toolbox.paragraphs
- (active, title, description, image, caption, back_to_top, page, pos)
- VALUES
- (TRUE, '','', '', '', FALSE, :page, 1)";
- $stmt = $this->_dbh->prepare($sql);
- $stmt->bindParam(':page', $pageId, PDO::PARAM_INT);
- return $stmt->execute();
- } catch(PDOException $e) {
- throw new RuntimeException(
- "Error creating paragraph {$e->getMessage()}"
- );
- }
- }
-}