Skip to content

Commit

Permalink
Merge pull request #50 from symfony-cmf/iks
Browse files Browse the repository at this point in the history
Iks branch merge
  • Loading branch information
lsmith77 committed Mar 25, 2012
2 parents c1a99ba + 2937c1a commit 63ee475
Show file tree
Hide file tree
Showing 23 changed files with 766 additions and 261 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ app/config/parameters.yml
nbproject
.idea
vagrant/.vagrant
.DS_Store
3 changes: 3 additions & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ liip_vie:
map:
'<http://rdfs.org/sioc/ns#Post>': 'Sandbox\MainBundle\Document\EditableStaticContent'
use_coffee: %liip_vie.use_coffee%
# TODO: these settings should come from the corresponding bundles, not be duplicated
base_path: /cms/routes
cms_path: /cms/content/static

sonata_block:
default_contexts: [cms]
Expand Down
12 changes: 12 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ test:
pattern: /hello
defaults: { _controller: SandboxTestBundle:Test:index }

image_upload:
pattern: /image/upload/
defaults: { _controller: sandbox_main.image_controller:uploadAction, _format: json }
requirements:
_format: json

image_display:
pattern: /image/{id}
defaults: { _controller: sandbox_main.image_controller:displayAction }
requirements:
id: '[A-Za-z0-9\.]+'

vie:
resource: "@LiipVieBundle/Resources/config/routing/phpcr_odm.xml"

Expand Down
32 changes: 16 additions & 16 deletions deps.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
symfony 632077aa819d0321e74a2f1b9d388af88bdcac0d
symfony ffddddb3ea7c03ac15f9e7725eb0b3aaa8bc26a6
twig 30929fde86f5ee12c863a3b572b0457ce52c140b
monolog b704c49a3051536f67f2d39f13568f74615b9922
MonologBundle 289442e385e7c0fe4aa2e8884d11e774a8f9ad99
doctrine-common d62352cc721fd05001eacdf0b527a142d3219e0f
jackalope 151cf1c4d88bd4daba521df6e947f80adc524f12
jackalope-jackrabbit a8043d466f7bb62ac9b9916fdf74df9ddbe741ab
jackalope-doctrine-dbal caec879788519cc6d0f9cfc2483e5b242c60f298
jackalope 6dc23881a12d3f98ce6cef240efd60e83c4caa12
jackalope-jackrabbit fa1f7e97f6041cf103cafcf122dd96b618895e1f
jackalope-doctrine-dbal f80826ace27bda81eea5f96cc1bb45ad6378775b
DoctrineBundle 90e39fb7ff5b4c13577602dab7e08c90067160b4
doctrine-dbal 220a5b0a05214d19dceea01e648d1413bba243c3
doctrine-dbal d9c3509e8d8fd8cb3887930c1d701ec118579289
doctrine 1b2b831febb780d8153bc4f8684baa763dd8f177
phpcr 09b07493dc60a45ce69108eb60f3eec50f8d9dd8
phpcr-utils 992b32af975ec7c3a3eb0032aa812487ea7172d4
doctrine-phpcr-odm 4c015c6aa48f58d0c35303e648c98d3810f098f7
DoctrinePHPCRBundle d221cd28dbb5287224b785b9e51fc1d59b3cfad1
phpcr 45bb7a8bbfbf175afb5abe64f115a9c5c8e454a2
phpcr-utils c9c4dcef8f3da099550a66d94120b68ed7dbfc1e
doctrine-phpcr-odm c4fc642c872e0eef699c50beeae90b821ea7cfbc
DoctrinePHPCRBundle 7213f0b8b02481b8d2811c0d488061dcf8b94081
DoctrineFixturesBundle 0e4e56b1da7981bcc7729e0f301a75195d34df18
doctrine-data-fixtures aea0b95a554188892f10d8f09ce3ae8150f28f8b
swiftmailer 982b4c9498b7dd85e70f6d35e65d909c888e6345
Expand All @@ -21,19 +21,19 @@ assetic 2634d29cc193981761e3daf28e1afc6358bb43b1
twig-extensions 1dfff8e793f50f651c4f74f796c2c68a4aee3147
metadata 84088bc4f6e2387ec8b549bffc1e037107572f5a
AsseticBundle b9cff021abc3d9433a892fa9908d9856393c0d09
FunctionalTestBundle a4ec2097dc375eb81e46c8608f920c7069414548
FunctionalTestBundle 14a4ee55fc49757f44382d15486f7c5e3eb9c3f6
VieBundle 0433d0fa6051e78bae872f1caeb213bc89cb8409
FOSRest 5eb800bd63ba84e5fc7028386cb66373bc3efafc
FOSRestBundle c95088f6207e37afbfa24c9c81b62baca5f4ef89
FOSRestBundle c11ab9d990a1e0e979b1c8ab72cc9793b4b2dcb5
FOSJsRoutingBundle bc61ffe5c4186a8ac206a8c68de221bc48e8a436
JMSSerializerBundle 27fbaafc4dcfa7dae2160b4efde5f8543e2bc3f4
knp-menu f818c58d89885c5eb1e305f5b7360588fd49fbab
KnpMenuBundle 462b7b40e5c17813a6d14929d7bca7d0511c7736
symfony-cmf 247292f8a357414df036ea6cc5d1e08de826b8fb
JMSSerializerBundle 93d9e6d50d6901632b6d5fa2280718733ce9c4f2
knp-menu f7970583d4da8776c037e2d49878d8160361e373
KnpMenuBundle c20933d2b988a3bd0944a0fd9e00068c30f0d27f
symfony-cmf 6e1e3eb018ee8b14eb39cb153b6119f0da1164ed
ChainRoutingBundle edd9f9544eadedb142fefd3ea9bb0c3b293c59d5
SonataCacheBundle f82a6d42052b226b09e16a0b7d519ee8906c6cdc
SonataBlockBundle ff34c3fe75bcedc739f3d4f8ad7f0a3b840b75e4
SonatajQueryBundle 01ffb8d1a7a4bb3971aed003e4f1ef050a0701aa
SonataAdminBundle 89b8a91ed81e555bf668947631718f4838ca1186
SonataAdminBundle abf2df4642937f063936f3a9de328ea12b20113c
SonataDoctrinePHPCRAdminBundle beb8d31ac03a89c811f25ecde18dbe3e3d31cf48
TreeBundle 10e8c1b15902990f51e62a2f94bf7cacaa956074
197 changes: 197 additions & 0 deletions jack
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#!/bin/bash

cd $(dirname $0)

# use * for newest available locally
RABBITVERSION="2.4.0"

# one per line
MIRRORS="https://s3-eu-west-1.amazonaws.com/patched-jackrabbit/
http://mirror.switch.ch/mirror/apache/dist//jackrabbit/$RABBITVERSION"

action="$1"; shift
args="$*"

pidfile=${TMPDIR:-/tmp}/jack.pid

JAR=

usage() {
echo "usage: $(basename $0) <action> [args]"
echo
echo "actions:"
echo -e " start\t\tStarts jackrabbit in the background with the given arguments"
echo -e " stop\t\tStops jackrabbit"
echo -e " restart\tRestarts jackrabbit"
echo -e " status\tPrint current status of jackrabbit (running, stopped)"
echo -e " log\t\tTails the logfile"
echo -e " clear\t\tResets index"
echo -e " flush\t\tWipes the db"
echo -e " flush:article\tRemoves today's articles (alternatively, use 'all' for removing all articles or pass the subpath to delete, e.g., '2011/04/26')"

}

if [ -z "$action" ]; then
usage
exit 1
fi

# kills jackrabbit and sleeps till process dies
# prints the id of the process previously active process (or empty if it wasn't running)
stop_jackrabbit() {
local id=$(cat $pidfile 2>/dev/null)

if [ -n "$id" ]; then
kill $id 2>/dev/null

# wait till process dies
kill -0 $id
while [[ $? -eq 0 ]]; do
sleep 1
kill -0 $id 2>/dev/null
done
fi
rm -f $pidfile
echo $id
}

verify_jackrabbit() {
local name="jackrabbit-standalone-$RABBITVERSION.jar"
JAR="$(ls -1 $name 2>/dev/null | tail -n 1)"

if [ -z "$JAR" ]; then
if [ "$RABBITVERSION" = "*" ]; then
echo "No file found matching $name"
echo "Get it at http://mirror.switch.ch/mirror/apache/dist/jackrabbit/"
exit 1
fi

read -p "$name not found. Download? [y/N] "
echo
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
JAR="$name"

echo "Be patient, this might take a minute..."
for m in $MIRRORS; do
url="${m%/}/$name"
echo -n "Downloading from $url"
code=$(curl -w %{http_code} -s $url -o jackrabbit.jar.tmp)
if [ $code != "200" ]; then
echo " [FAILED: $code]"
continue
fi
echo " [OKAY]"
mv jackrabbit.jar.tmp $name
done
rm -f jackrabbit.jar.tmp
fi
}

# starts jackrabbit in the background
start_jackrabbit() {

verify_jackrabbit

if [ -e "$JAR" ]; then

# already running?
if [ -e $pidfile ]; then
echo "jackrabbit seems to be running ($pidfile)"
echo "Use \`jack restart\` or \`jack stop\`"
exit 1
fi

echo "Starting in the background using: $JAR"
java -Xmx512m -Xms512m -jar $JAR $args &
echo $! > $pidfile

else
echo "File not found: $JAR"
exit 1
fi
}

status_jackrabbit() {
if [ ! -e $pidfile ]; then
echo "Not running ($pidfile not found)"
else
echo "Running ($pidfile says $(cat $pidfile))"
fi
}


case "$action" in
clear)
wasrunning=$(stop_jackrabbit)
rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz/index
rm -rf jackrabbit/workspaces/nzz_test/index
echo 'Cleared repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;
flush:article)
[ -z $args ] && args=$(date +%Y/%m/%d)
[ $args = "all" ] && args=""
# TODO extract port from $args
curl -X DELETE http://admin:admin@localhost:8080/server/nzz/jcr:root/article/$args
;;

flush)
read -p "This will truncate the DB. Continue? [y/N]"
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
wasrunning=$(stop_jackrabbit)
rm -rf jackrabbit/repository/datastore
rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz/index
rm -rf jackrabbit/workspaces/nzz/db
rm -rf jackrabbit/version
echo 'Flushed repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;

flush:test)
read -p "This will truncate the test DB. Continue? [y/N]"
if [[ ! $REPLY =~ [Yy] ]]; then
exit
fi
wasrunning=$(stop_jackrabbit)
# rm -rf jackrabbit/repository/datastore
# rm -rf jackrabbit/repository/index
rm -rf jackrabbit/workspaces/nzz_test/index
rm -rf jackrabbit/workspaces/nzz_test/db
rm -rf jackrabbit/version
echo 'Flushed repository and workspace.'
[ $wasrunning ] && start_jackrabbit
;;

register)
app/console doctrine:phpcr:register-system-node-types --allow-update
app/console doctrine:phpcr:register-node-types ./script/nzz_unstructure.cnd --allow-update
;;
log)
tail -f jackrabbit/log/jackrabbit.log
;;
stop)
stop_jackrabbit >/dev/null
;;
restart)
stop_jackrabbit >/dev/null
start_jackrabbit
;;
start)
start_jackrabbit
;;
status)
status_jackrabbit
;;

*)
echo "Unknown action: $action"
usage
exit 1
esac

2 changes: 1 addition & 1 deletion src/Sandbox/AdminBundle/Admin/ContentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function configureFormFields(FormMapper $formMapper)
->add('path', 'text')
->add('title')
->add('name')
->add('content', 'text')
->add('content', 'textarea')
->end();
}

Expand Down
99 changes: 99 additions & 0 deletions src/Sandbox/MainBundle/Controller/ImageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Sandbox\MainBundle\Controller;

use Sandbox\MainBundle\Document\Image;

use Doctrine\ODM\PHPCR\DocumentManager;

use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ImageController extends Controller
{
protected $dm;

/**
* @var FOS\RestBundle\View\ViewHandlerInterface
*/
private $viewHandler;

protected $images_mime = array(
'image/png',
'image/jpeg',
'image/gif',
'image/bmp',
'image/vnd.microsoft.icon',
'image/tiff',
'image/svg+xml');

public function __construct(ContainerInterface $container, DocumentManager $dm, ViewHandlerInterface $viewHandler)
{
$this->container = $container;
$this->dm = $dm;
$this->viewHandler = $viewHandler;
}

public function displayAction($id)
{
$basepath = $this->container->getParameter('symfony_cmf_content.static_basepath');

$image = $this->dm->find(null, $basepath.'/'.$id);

$data = stream_get_contents($image->content);

$response = new Response($data);
$response->headers->set('Content-Type', 'image/jpeg');
$response->setPublic();

$date = new \DateTime();
$date->setTimestamp(time() + 332640000);
$response->setExpires($date);
$response->setMaxAge(332640000);

return $response;
}

public function uploadAction(Request $request)
{
$basepath = $this->container->getParameter('symfony_cmf_content.static_basepath');
$error = false;
$path = '';

$files = $request->files;

$id = '';
foreach ($files->all() as $file ) {
if (in_array($file->getClientMimeType(), $this->images_mime)) {
$name = $file->getClientOriginalName();
$path = $file->getPathname();
$id = md5(time());
$jcrPath = $basepath.'/'.$id;
if (!$this->dm->find(null, $jcrPath)) {
$image = new Image();
$image->setPath($jcrPath);
$image->name = $id;
$image->content = file_get_contents($path);
$image->tags = explode(',', $request->get('tags'));
} else {
$error = 'This file already exists in your backend.';
}

$this->dm->persist($image);
} else {
$error = "What you're trying to upload is not an image.";
}
}

$this->dm->flush();

return $this->redirect($this->generateUrl('image_display', array('id' => $id)));
}
}

0 comments on commit 63ee475

Please sign in to comment.